home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 12 / Cream of the Crop 12 (Part II) / Cream of the Crop 12 (Part II).iso / OS2 / MEMSZ312.ZIP / SOURCE.ZIP / MEMSIZE.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-19  |  137.8 KB  |  3,243 lines

  1. /**************************************************************** MEMSIZE.CPP
  2.  *                                                                          *
  3.  * System Resources Monitor                                                 *
  4.  *                                                                          *
  5.  * (C) Copyright 1991-1995 by Richard W. Papo.                              *
  6.  *                                                                          *
  7.  * This is 'FreeWare'.  As such, it may be copied and distributed           *
  8.  * freely.  If you want to use part of it in your own program, please       *
  9.  * give credit where credit is due.  If you want to change the              *
  10.  * program, please refer the change request to me or send me the            *
  11.  * modified source code.  I can be reached at CompuServe 72607,3111         *
  12.  * and on Internet at RPapo@Msen.com.                                       *
  13.  *                                                                          *
  14.  ****************************************************************************/
  15.  
  16. // Bugs to Fix:
  17. //
  18. //   (1) When Float To Top is active, then the E editor dies upon displaying
  19. //       its file-type-set dialog.  CLOCK has the same problem.  IBM's bug, which
  20. //       was fixed with the Warp FixPak 17.
  21. //
  22. //   (2) Fix one bug, cause another (it seems).  When the Warp FixPak 17 has been 
  23. //       installed, then the window will not bring itself to the top of the Z-order 
  24. //       with a simple mouse click in the usual way.  Once the Context Menu has 
  25. //       been summoned (even once) the window behaves normally again.  I have been 
  26. //       unable to determine the cause of this.
  27. //
  28. //   (3) Drive space overflow when individual drives exceed 4GB in size.
  29. //
  30. //
  31. // Things to do:
  32. //
  33. //   (1) Add option for configuring the time/date field's justification (left/center/right).
  34. //
  35. //   (2) Add menu option to reset drives, and do so automatically once in a while.
  36. //
  37. //   (3) Revise ResetDefaults to reset -all- defaults, including monitor priority, anchor, etc.
  38. //
  39. //   (4) Add option for year in date.
  40. //
  41. //   (5) Add displayable item for Average CPU Load.  Add menu item to reset it.
  42. //
  43. //
  44.  
  45. #define INCL_BASE
  46. #define INCL_PM
  47. #include <os2.h>
  48.  
  49. #include <stdio.h>
  50. #include <stdlib.h>
  51. #include <string.h>
  52. #include <time.h>
  53.  
  54. #include "Dde.h"
  55. #include "Debug.h"
  56. #include "DQPS.h"
  57. #include "Event.h"
  58. #include "Except.h"
  59. #include "HelpWin.h"
  60. #include "Module.h"
  61. #include "Process.h"
  62. #include "Profile.h"
  63. #include "ReString.h"
  64. #include "Support.h"
  65. #include "Thread.h"
  66. #include "Window.h"
  67.  
  68. #include "About.h"
  69. #include "Config.h"
  70.  
  71. #include "Items.h"
  72.  
  73. #include "MemSize.h"
  74.  
  75. #define STATIC
  76.  
  77.  
  78. /****************************************************************************
  79.  *                                                                          *
  80.  *                       Definitions & Declarations                         *
  81.  *                                                                          *
  82.  ****************************************************************************/
  83.  
  84.   // Constants
  85.  
  86. #define WM_REFRESH        (WM_USER)
  87.  
  88.  
  89.   // Data Types
  90.  
  91. typedef struct {
  92.    BOOL Active ;
  93.    PULONG Counter ;
  94.    PUSHORT Interval ;
  95.    PBYTE Priority ;
  96.    HWND Owner ;
  97. } MONITOR_PARMS, *PMONITOR_PARMS ;
  98.  
  99. typedef struct {
  100.    BOOL Active ;
  101.    ULONG Counter ;
  102. } COUNTER_PARMS, *PCOUNTER_PARMS ;
  103.  
  104. typedef struct {      // Data structure for window.
  105.    Process       *Proc ;
  106.    Module        *Library ;
  107.    Profile       *IniFile ;
  108.  
  109.    INIDATA        IniData ;
  110.  
  111.    TID            CounterTID ;
  112.    COUNTER_PARMS  CounterParms ;
  113.  
  114.    TID            MonitorTID ;
  115.    MONITOR_PARMS  MonitorParms ;
  116.  
  117.    HWND           TitleBar ;
  118.    HWND           SysMenu ;
  119.    HWND           MinMax ;
  120.    HWND           Menu ;
  121.  
  122.    ULONG          Drives ;
  123.  
  124.    long           Width ;
  125.    long           Height ;
  126.    int            MaxColumns ;
  127.  
  128.    FONTMETRICS    FontMetrics ;
  129.    LONG           CharMode ;
  130.    SIZEF          CharBox ;
  131.  
  132.    Dde_Server    *pDdeServer ;
  133.  
  134. } DATA, *PDATA ;
  135.  
  136. typedef struct {
  137.    short Filler ;
  138.    Process *Proc ;
  139.    Module *Library ;
  140.    Profile *IniFile ;
  141. } PARMS, *PPARMS ;
  142.  
  143.  
  144.   // Function Prototypes
  145.  
  146. extern int main ( int argc, char *argv[] ) ;
  147.  
  148. STATIC FNWP MessageProcessor ;
  149.  
  150. STATIC FNWP Create ;
  151. STATIC FNWP Destroy ;
  152. STATIC FNWP Size ;
  153. STATIC FNWP SaveApplication ;
  154. STATIC FNWP Paint ;
  155. static FNWP InitMenu ;
  156. STATIC FNWP Command ;
  157. STATIC FNWP ResetDefaults ;
  158. STATIC FNWP HideControlsCmd ;
  159. STATIC FNWP Configure ;
  160. STATIC FNWP ResetLoad ;
  161. STATIC FNWP Copy ;
  162. STATIC FNWP About ;
  163. STATIC FNWP BeginDrag ;
  164. STATIC FNWP ButtonDblClick ;
  165. STATIC FNWP ContextMenu ;
  166. STATIC FNWP PresParamChanged ;
  167. STATIC FNWP SysColorChange ;
  168. STATIC FNWP QueryKeysHelp ;
  169. STATIC FNWP HelpError ;
  170. STATIC FNWP ExtHelpUndefined ;
  171. STATIC FNWP HelpSubitemNotFound ;
  172. STATIC FNWP Refresh ;
  173. STATIC FNWP Dde_Initiate ;
  174.  
  175. STATIC int GetIniData ( HAB Anchor, HMODULE Library, HINI IniHandle, PINIDATA IniData, Dde_Server *pDdeServer ) ;
  176. STATIC PSZ ScanSystemConfig ( HAB Anchor, PSZ Keyword ) ;
  177. STATIC char *CopyString ( char *Buffer, char *Original ) ;
  178.  
  179. STATIC void ResizeWindow ( HWND hwnd ) ;
  180.  
  181. STATIC void HideControls ( BOOL fHide, HWND Frame,
  182.    HWND SysMenu, HWND TitleBar, HWND MinMax ) ;
  183.  
  184. STATIC void UpdateWindow ( HWND hwnd, PDATA Data, BOOL All ) ;
  185.  
  186. STATIC VOID MonitorLoopThread ( PVOID Parameter ) ;
  187.  
  188. STATIC VOID UpdateDriveList (
  189.    HAB Anchor, HMODULE Library, HINI IniHandle, PINIDATA IniData,
  190.    Dde_Server *pDdeServer, ULONG OldDrives, ULONG NewDrives ) ;
  191.  
  192. STATIC int CheckDrive ( USHORT Drive, PBYTE FileSystem, PBYTE DiskLabel ) ;
  193.  
  194. STATIC ULONG CalibrateLoadMeter ( PCOUNTER_PARMS Parms ) ;
  195.  
  196. STATIC VOID CounterThread ( PVOID Parameter ) ;
  197.  
  198.  
  199.   // Global Data
  200.  
  201. static Process Proc ;                           // Must be declared first.
  202. static Module Library ( PSZ(PROGRAM_NAME) ) ;
  203.  
  204. static Event CounterThreadEvent = Event ( ) ;
  205. static Event MonitorThreadEvent = Event ( ) ;
  206.  
  207. HMODULE LibraryHandle ;
  208.  
  209.  
  210. /****************************************************************************
  211.  *                                                                          *
  212.  *      Program Mainline                                                    *
  213.  *                                                                          *
  214.  ****************************************************************************/
  215.  
  216. extern int main ( int argc, char *argv[] ) {
  217.  
  218.  /***************************************************************************
  219.   * Save the resource library handle for the exception handler to use.      *
  220.   ***************************************************************************/
  221.  
  222.   LibraryHandle = Library.QueryHandle() ;
  223.  
  224.  /***************************************************************************
  225.   * Get the program title.                                                  *
  226.   ***************************************************************************/
  227.  
  228.   ResourceString Title ( Library.QueryHandle(), IDS_TITLE ) ;
  229.  
  230.  /***************************************************************************
  231.   * Set the codepage.  Abort if unable to do so.                            *
  232.   ***************************************************************************/
  233.  
  234.   PVOID Offset ;
  235.   DosGetResource ( Library.QueryHandle(), RT_RCDATA, 1, &Offset ) ;
  236.  
  237.   PUSHORT pCodePage = PUSHORT ( Offset ) ;
  238.  
  239.   while ( *pCodePage ) {
  240.      if ( !DosSetProcessCp ( *pCodePage ) ) 
  241.         if ( WinSetCp ( Proc.QueryQueue(), *pCodePage ) ) 
  242.            break ;
  243.      pCodePage ++ ;
  244.   } /* endwhile */
  245.  
  246.   if ( *pCodePage == 0 ) {
  247.      ResourceString Format ( Library.QueryHandle(), IDS_ERROR_BADCODEPAGE ) ;
  248.      CHAR Message [200] ;
  249.      sprintf ( Message, PCHAR(Format), *pCodePage ) ;
  250.      Log ( "%s", Message ) ;
  251.      WinMessageBox ( HWND_DESKTOP, HWND_DESKTOP, PSZ(Message),
  252.         PSZ(Title), 0, MB_ENTER | MB_ICONEXCLAMATION ) ;
  253.      return ( 1 ) ;
  254.   } /* endif */
  255.  
  256.  /***************************************************************************
  257.   * Decipher command-line parameters.                                       *
  258.   ***************************************************************************/
  259.  
  260.   BOOL Reset = FALSE ;
  261.  
  262.   ResourceString ResetCommand ( Library.QueryHandle(), IDS_PARMS_RESET ) ;
  263.  
  264.   while ( --argc ) {
  265.  
  266.      argv ++ ;
  267.  
  268.      if ( *argv[0] == '?' ) {
  269.         ResourceString Message ( Library.QueryHandle(), IDS_PARAMETERLIST ) ;
  270.         WinMessageBox ( HWND_DESKTOP, HWND_DESKTOP, PSZ(Message),
  271.            PSZ(Title), 0, MB_ENTER | MB_NOICON ) ;
  272.         return ( 0 ) ;
  273.      } /* endif */
  274.  
  275.      if ( !stricmp ( *argv, PCHAR(ResetCommand) ) ) {
  276.         Reset = TRUE ;
  277.         continue ;
  278.      } /* endif */
  279.  
  280.      #if 0
  281.      ResourceString Format ( Library.QueryHandle(), IDS_ERROR_INVALIDPARM ) ;
  282.      BYTE Message [200] ;
  283.      sprintf ( PCHAR(Message), PCHAR(Format), *argv ) ;
  284.      WinMessageBox ( HWND_DESKTOP, HWND_DESKTOP, Message,
  285.         PSZ(Title), 0, MB_ENTER | MB_ICONEXCLAMATION ) ;
  286.      return ( 1 ) ;
  287.      #endif
  288.  
  289.   } /* endwhile */
  290.  
  291.  /***************************************************************************
  292.   * Create the help instance.                                               *
  293.   ***************************************************************************/
  294.  
  295.   ResourceString HelpTitle ( Library.QueryHandle(), IDS_HELPTITLE ) ;
  296.  
  297.   HelpWindow Help ( Proc.QueryAnchor(), 0,
  298.      ID_MAIN, PSZ(PROGRAM_NAME ".hlp"), PSZ(HelpTitle) ) ;
  299.  
  300.   if ( Help.QueryHandle() == 0 ) {
  301.      ERRORID Error = WinGetLastError ( Proc.QueryAnchor() ) ;
  302.      ResourceString Format ( Library.QueryHandle(), IDS_ERROR_CREATEHELP ) ;
  303.      CHAR Message [200] ;
  304.      sprintf ( Message, PCHAR(Format), Error ) ;
  305.      Log ( "%s", Message ) ;
  306.      WinMessageBox ( HWND_DESKTOP, HWND_DESKTOP, PSZ(Message),
  307.         PSZ(Title), 0, MB_ENTER | MB_ICONEXCLAMATION ) ;
  308.   } /* endif */
  309.  
  310.  /***************************************************************************
  311.   * Open/create the profile file.  Reset if requested.                      *
  312.   ***************************************************************************/
  313.  
  314.   Profile IniFile ( PSZ(PROGRAM_NAME),
  315.      Proc.QueryAnchor(), Library.QueryHandle(),
  316.      IDD_PROFILE_PATH, Help.QueryHandle(), Reset ) ;
  317.  
  318.   if ( IniFile.QueryHandle() == 0 ) {
  319.      ResourceString Message ( Library.QueryHandle(), IDS_ERROR_PRFOPENPROFILE ) ;
  320.      Log ( "%s", PSZ(Message) ) ;
  321.      WinMessageBox ( HWND_DESKTOP, HWND_DESKTOP, PSZ(Message),
  322.         PSZ(Title), 0, MB_ENTER | MB_ICONEXCLAMATION ) ;
  323.      return ( 2 ) ;
  324.   } /* endif */
  325.  
  326.  /***************************************************************************
  327.   * Read the profile to find out if we're to animate the frame window.      *
  328.   ***************************************************************************/
  329.  
  330.   INIDATA IniData ;
  331.   if ( GetIniData ( HINI_USERPROFILE, &IniData ) ) {
  332.      GetIniData ( IniFile.QueryHandle(), &IniData ) ;
  333.   } else {
  334.      PutIniData ( IniFile.QueryHandle(), &IniData ) ;
  335.      PrfWriteProfileData ( HINI_USERPROFILE, PSZ(PROGRAM_NAME), 0, 0, 0 ) ;
  336.   } /* endif */
  337.  
  338.  /***************************************************************************
  339.   * Create the frame window.                                                *
  340.   ***************************************************************************/
  341.  
  342.   FRAMECDATA FrameControlData ;
  343.   FrameControlData.cb = sizeof(FrameControlData) ;
  344.   FrameControlData.flCreateFlags =
  345.      FCF_TITLEBAR | FCF_SYSMENU | FCF_BORDER |
  346.      FCF_ICON | FCF_MINBUTTON | FCF_NOBYTEALIGN | FCF_ACCELTABLE ;
  347.   FrameControlData.hmodResources = 0 ;
  348.   FrameControlData.idResources = ID_MAIN ;
  349.  
  350.   Window Frame ( HWND_DESKTOP, WC_FRAME, PSZ(Title),
  351.      IniData.fAnimate AND IniData.Animate ? WS_ANIMATE : 0,
  352.      0, 0, 0, 0, HWND_DESKTOP, HWND_TOP, ID_MAIN,
  353.      &FrameControlData, NULL ) ;
  354.  
  355.   if ( Frame.QueryHandle() == 0 ) {
  356.      ERRORID Error = WinGetLastError ( Proc.QueryAnchor() ) ;
  357.      ResourceString Format ( Library.QueryHandle(), IDS_ERROR_CREATEFRAME ) ;
  358.      CHAR Message [200] ;
  359.      sprintf ( Message, PCHAR(Format), Error ) ;
  360.      Log ( "%s", Message ) ;
  361.      WinMessageBox ( HWND_DESKTOP, HWND_DESKTOP, PSZ(Message),
  362.         PSZ(Title), 0, MB_ENTER | MB_ICONEXCLAMATION ) ;
  363.      return ( 3 ) ;
  364.   } /* endif */
  365.  
  366.  /***************************************************************************
  367.   * Associate the help instance with the frame window.                      *
  368.   ***************************************************************************/
  369.  
  370.   if ( Help.QueryHandle() )
  371.      WinAssociateHelpInstance ( Help.QueryHandle(), Frame.QueryHandle() ) ;
  372.  
  373.  /***************************************************************************
  374.   * Register the client window class.                                       *
  375.   ***************************************************************************/
  376.  
  377.   if ( !WinRegisterClass ( Proc.QueryAnchor(), PSZ(CLASS_NAME),
  378.      MessageProcessor, CS_MOVENOTIFY, sizeof(PVOID) ) ) {
  379.      ERRORID Error = WinGetLastError ( Proc.QueryAnchor() ) ;
  380.      ResourceString Format ( Library.QueryHandle(), IDS_ERROR_WINREGISTERCLASS ) ;
  381.      CHAR Message [200] ;
  382.      sprintf ( Message, PCHAR(Format), CLASS_NAME, Error ) ;
  383.      Log ( "%s", Message ) ;
  384.      WinMessageBox ( HWND_DESKTOP, HWND_DESKTOP, PSZ(Message),
  385.         PSZ(Title), 0, MB_ENTER | MB_ICONEXCLAMATION ) ;
  386.      return ( 4 ) ;
  387.   } /* endif */
  388.  
  389.  /***************************************************************************
  390.   * Build the presentation parameters for the client window.                *
  391.   ***************************************************************************/
  392.  
  393.   USHORT ParmCount = 0 ;
  394.   ULONG Ids [3] ;
  395.   ULONG ByteCounts [3] ;
  396.   PBYTE Params [3] ;
  397.  
  398.   if ( IniData.fTextColor ) {
  399.      Ids [ParmCount] = PP_FOREGROUNDCOLOR ;
  400.      ByteCounts [ParmCount] = sizeof(IniData.TextColor) ;
  401.      Params [ParmCount++] = PBYTE ( &IniData.TextColor ) ;
  402.   } /* endif */
  403.  
  404.   if ( IniData.fBackColor ) {
  405.      Ids [ParmCount] = PP_BACKGROUNDCOLOR ;
  406.      ByteCounts [ParmCount] = sizeof(IniData.BackColor) ;
  407.      Params [ParmCount++] = PBYTE ( &IniData.BackColor ) ;
  408.   } /* endif */
  409.  
  410.   if ( IniData.fFontNameSize ) {
  411.      Ids [ParmCount] = PP_FONTNAMESIZE ;
  412.      ByteCounts [ParmCount] = strlen(PCHAR(IniData.FontNameSize)) + 1 ;
  413.      Params [ParmCount++] = PBYTE ( IniData.FontNameSize ) ;
  414.   } /* endif */
  415.  
  416.   PPRESPARAMS PresParams = BuildPresParams ( ParmCount, Ids, ByteCounts, Params ) ;
  417.  
  418.  /***************************************************************************
  419.   * Create the client window.                                               *
  420.   ***************************************************************************/
  421.  
  422.   PARMS Parms ;
  423.   Parms.Filler = 0 ;
  424.   Parms.Proc = & Proc ;
  425.   Parms.Library = & Library ;
  426.   Parms.IniFile = & IniFile ;
  427.  
  428.   Window Client ( Frame.QueryHandle(), PSZ(CLASS_NAME), PSZ(""), 0, 0, 0, 0, 0,
  429.      Frame.QueryHandle(), HWND_BOTTOM, FID_CLIENT, &Parms, PresParams ) ;
  430.  
  431.   if ( Client.QueryHandle() == 0 ) {
  432.      ERRORID Error = WinGetLastError ( Proc.QueryAnchor() ) ;
  433.      ResourceString Format ( Library.QueryHandle(), IDS_ERROR_CREATECLIENT ) ;
  434.      CHAR Message [200] ;
  435.      sprintf ( Message, PCHAR(Format), Error ) ;
  436.      Log ( "%s", Message ) ;
  437.      WinMessageBox ( HWND_DESKTOP, HWND_DESKTOP, PSZ(Message),
  438.         PSZ(Title), 0, MB_ENTER | MB_ICONEXCLAMATION ) ;
  439.      return ( 5 ) ;
  440.   } /* endif */
  441.  
  442.  /***************************************************************************
  443.   * Wait for and process messages to the window's queue.  Terminate         *
  444.   *   when the WM_QUIT message is received.                                 *
  445.   ***************************************************************************/
  446.  
  447.   QMSG QueueMessage ;
  448.   while ( WinGetMsg ( Proc.QueryAnchor(), &QueueMessage, 0, 0, 0 ) ) {
  449.      WinDispatchMsg ( Proc.QueryAnchor(), &QueueMessage ) ;
  450.   } /* endwhile */
  451.  
  452.  /***************************************************************************
  453.   * Discard all that was requested of the system and terminate.             *
  454.   ***************************************************************************/
  455.  
  456.   return ( 0 ) ;
  457. }
  458.  
  459. /****************************************************************************
  460.  *                                                                          *
  461.  *      Window Message Processor                                            *
  462.  *                                                                          *
  463.  ****************************************************************************/
  464.  
  465. STATIC MRESULT EXPENTRY MessageProcessor ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  466.  
  467.   /**************************************************************************
  468.    * Dispatch the message according to the method table and return the      *
  469.    *   result.  Any messages not defined above get handled by the system    *
  470.    *   default window processor.                                            *
  471.    **************************************************************************/
  472.  
  473.    static METHOD Methods [] = {
  474.       { WM_CREATE,                Create              },
  475.       { WM_DESTROY,               Destroy             },
  476.       { WM_SIZE,                  Size                },
  477.       { WM_MOVE,                  Size                },
  478.       { WM_SAVEAPPLICATION,       SaveApplication     },
  479.       { WM_PAINT,                 Paint               },
  480.       { WM_INITMENU,              InitMenu            },
  481.       { WM_COMMAND,               Command             },
  482.       { WM_BEGINSELECT,           BeginDrag           },
  483.       { WM_BEGINDRAG,             BeginDrag           },
  484.       { WM_BUTTON1DBLCLK,         ButtonDblClick      },
  485.       { WM_CONTEXTMENU,           ContextMenu         },
  486.       { WM_PRESPARAMCHANGED,      PresParamChanged    },
  487.       { WM_SYSCOLORCHANGE,        SysColorChange      },
  488.       { HM_QUERY_KEYS_HELP,       QueryKeysHelp       },
  489.       { HM_ERROR,                 HelpError           },
  490.       { HM_EXT_HELP_UNDEFINED,    ExtHelpUndefined    },
  491.       { HM_HELPSUBITEM_NOT_FOUND, HelpSubitemNotFound },
  492.       { WM_REFRESH,               Refresh             },
  493.       { WM_DDE_INITIATE,          Dde_Initiate        },
  494.    } ;
  495.  
  496.    #ifdef DEBUG
  497.    static int Indent = 0 ;
  498.    Log ( "%*sMAIN: Message %08X received.  Parm1=%08X, Parm2=%08X.", Indent, "", msg, mp1, mp2 ) ;
  499.    Indent += 2 ;
  500.    #endif
  501.  
  502.    MRESULT Result = DispatchMessage ( hwnd, msg, mp1, mp2, Methods, sizeof(Methods)/sizeof(Methods[0]), WinDefWindowProc ) ;
  503.  
  504.    #ifdef DEBUG
  505.    Indent -= 2 ;
  506.    Log ( "%*sMAIN: Message %08X done.  Result %08X.", Indent, "", msg, Result ) ;
  507.    #endif
  508.  
  509.    return ( Result ) ;
  510. }
  511.  
  512. /****************************************************************************
  513.  *                                                                          *
  514.  *      Create the main window.                                             *
  515.  *                                                                          *
  516.  ****************************************************************************/
  517.  
  518. STATIC MRESULT APIENTRY Create ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  519.  
  520.  /***************************************************************************
  521.   * Allocate instance data.                                                 *
  522.   ***************************************************************************/
  523.  
  524.   PDATA Data = PDATA ( malloc ( sizeof(DATA) ) ) ;
  525.  
  526.   memset ( Data, 0, sizeof(DATA) ) ;
  527.  
  528.   WinSetWindowPtr ( hwnd, QWL_USER, Data ) ;
  529.  
  530.  /***************************************************************************
  531.   * Grab any parameters from the WM_CREATE message.                         *
  532.   ***************************************************************************/
  533.  
  534.   PPARMS Parms = PPARMS ( PVOIDFROMMP ( mp1 ) ) ;
  535.  
  536.   Data->Proc = Parms->Proc ;
  537.   Data->Library = Parms->Library ;
  538.   Data->IniFile = Parms->IniFile ;
  539.  
  540.  /***************************************************************************
  541.   * Initialize the DDE Server.                                              *
  542.   ***************************************************************************/
  543.  
  544.   Data->pDdeServer = new Dde_Server ( Data->Proc->QueryAnchor(),
  545.      Data->Library->QueryHandle(), hwnd, PROGRAM_NAME ) ;
  546.  
  547.   Data->pDdeServer->AddTopic ( SZDDESYS_TOPIC, SZDDESYS_ITEM_SYSITEMS ) ;
  548.  
  549.   char *Topics = SZDDESYS_TOPIC "\t" "Items" ;
  550.   Data->pDdeServer->AddItem ( SZDDESYS_TOPIC, SZDDESYS_ITEM_TOPICS, DDEFMT_TEXT, Topics, strlen(Topics)+1 ) ;
  551.  
  552.   char *Protocols = "" ;
  553.   Data->pDdeServer->AddItem ( SZDDESYS_TOPIC, SZDDESYS_ITEM_PROTOCOLS, DDEFMT_TEXT, Protocols, strlen(Protocols)+1 ) ;
  554.  
  555.   Data->pDdeServer->AddTopic ( "Items", "Items" ) ;
  556.  
  557.  /***************************************************************************
  558.   * Load the window context menu.                                           *
  559.   ***************************************************************************/
  560.  
  561.   Data->Menu = WinLoadMenu ( HWND_DESKTOP, Data->Library->QueryHandle(), IDM_MENU ) ;
  562.   if ( Data->Menu == 0 ) {
  563.      ERRORID Error = WinGetLastError ( Data->Proc->QueryAnchor() ) ;
  564.      Log ( "WARNING: Unable to create context menu.  Error %08lX.", Error ) ;
  565.   } /* endif */
  566.  
  567.  /***************************************************************************
  568.   * Get the current drive mask.                                             *
  569.   ***************************************************************************/
  570.  
  571.   ULONG Drive ;
  572.   DosQueryCurrentDisk ( &Drive, &Data->Drives ) ;
  573.  
  574.  /***************************************************************************
  575.   * Calibrate the old-style load meter, if the high resolution timer's      *
  576.   *   available.                                                            *
  577.   ***************************************************************************/
  578.  
  579.   Data->IniData.MaxCount = CalibrateLoadMeter ( &Data->CounterParms ) ;
  580.   Data->IniData.MaxCount = (ULONG) max ( 1, Data->IniData.MaxCount ) ;
  581.  
  582.  /***************************************************************************
  583.   * Get profile data. Try the OS2.INI first, then try for private INI.      *
  584.   *   If obtained from OS2.INI, erase it afterwards.                        *
  585.   ***************************************************************************/
  586.  
  587.   if ( GetIniData ( Data->Proc->QueryAnchor(), Data->Library->QueryHandle(), HINI_USERPROFILE, &Data->IniData, Data->pDdeServer ) ) {
  588.      GetIniData ( Data->Proc->QueryAnchor(), Data->Library->QueryHandle(), Data->IniFile->QueryHandle(), &Data->IniData, Data->pDdeServer ) ;
  589.   } else {
  590.      PutIniData ( Data->IniFile->QueryHandle(), &Data->IniData ) ;
  591.      PrfWriteProfileData ( HINI_USERPROFILE, PSZ(PROGRAM_NAME), 0, 0, 0 ) ;
  592.   } /* endif */
  593.  
  594.  /***************************************************************************
  595.   * Get the frame handle.                                                   *
  596.   ***************************************************************************/
  597.  
  598.   HWND Frame = WinQueryWindow ( hwnd, QW_PARENT ) ;
  599.  
  600.  /***************************************************************************
  601.   * Get the control window handles.                                         *
  602.   ***************************************************************************/
  603.  
  604.   Data->SysMenu  = WinWindowFromID ( Frame, FID_SYSMENU  ) ;
  605.   Data->TitleBar = WinWindowFromID ( Frame, FID_TITLEBAR ) ;
  606.   Data->MinMax   = WinWindowFromID ( Frame, FID_MINMAX   ) ;
  607.  
  608.  /***************************************************************************
  609.   * Add basic extensions to the system menu.                                *
  610.   ***************************************************************************/
  611.  
  612.   static MENUITEM MenuSeparator =
  613.      { MIT_END, MIS_SEPARATOR, 0, 0, 0, 0 } ;
  614.  
  615.   AddSysMenuItem ( Frame, &MenuSeparator, 0 ) ;
  616.  
  617.   static MENUITEM MenuItems [] = {
  618.      { MIT_END, MIS_TEXT,      0, IDM_SAVE_APPLICATION, 0, 0 },
  619.      { MIT_END, MIS_TEXT,      0, IDM_RESET_DEFAULTS,   0, 0 },
  620.      { MIT_END, MIS_TEXT,      0, IDM_HIDE_CONTROLS,    0, 0 },
  621.      { MIT_END, MIS_TEXT,      0, IDM_CONFIGURE,        0, 0 },
  622.      { MIT_END, MIS_TEXT,      0, IDM_RESETLOAD,        0, 0 },
  623.      { MIT_END, MIS_TEXT,      0, IDM_COPY,             0, 0 },
  624.   } ;
  625.  
  626.   for ( int i=0; i<sizeof(MenuItems)/sizeof(MenuItems[0]); i++ ) {
  627.      ResourceString MenuText ( Data->Library->QueryHandle(), i+IDS_SAVE_APPLICATION ) ;
  628.      AddSysMenuItem ( Frame, MenuItems+i, PSZ(MenuText) ) ;
  629.   } /* endfor */
  630.  
  631.   AddSysMenuItem ( Frame, &MenuSeparator, 0 ) ;
  632.  
  633.  /***************************************************************************
  634.   * Add 'About' to the system menu.                                         *
  635.   ***************************************************************************/
  636.  
  637.   static MENUITEM MenuAbout =
  638.     { MIT_END, MIS_TEXT, 0, IDM_ABOUT, 0, 0 } ;
  639.  
  640.   ResourceString AboutText ( Data->Library->QueryHandle(), IDS_ABOUT ) ;
  641.  
  642.   AddSysMenuItem ( Frame, &MenuAbout, PSZ(AboutText) ) ;
  643.  
  644.  /***************************************************************************
  645.   * Add 'Help' to the system menu.                                          *
  646.   ***************************************************************************/
  647.  
  648.   static MENUITEM MenuHelp =
  649.     { MIT_END, MIS_HELP, 0, 0, 0, 0 } ;
  650.  
  651.   ResourceString HelpText ( Data->Library->QueryHandle(), IDS_HELP ) ;
  652.  
  653.   AddSysMenuItem ( Frame, &MenuHelp, PSZ(HelpText) ) ;
  654.  
  655.  /***************************************************************************
  656.   * Start the new load meter.                                               *
  657.   ***************************************************************************/
  658.  
  659.   CounterThreadEvent.Reset ( ) ;
  660.   Data->CounterParms.Active = TRUE ;
  661.   Data->CounterTID = StartThread ( "CounterThread", CounterThread, 0x3000, &Data->CounterParms ) ;
  662.   DosSuspendThread ( Data->CounterTID ) ;
  663.   DosSetPriority ( PRTYS_THREAD, PRTYC_IDLETIME, PRTYD_MINIMUM, Data->CounterTID ) ;
  664.  
  665.   Data->IniData.IdleCount = 0 ;
  666.   Data->CounterParms.Counter = 0 ;
  667.  
  668.   if ( Data->IniData.Items[ITEM_CPULOAD].pItem->QueryFlag() )
  669.      DosResumeThread ( Data->CounterTID ) ;
  670.  
  671.   MonitorThreadEvent.Reset ( ) ;
  672.   Data->MonitorParms.Active = TRUE ;
  673.   Data->MonitorParms.Counter = & Data->CounterParms.Counter ;
  674.   Data->MonitorParms.Interval = & Data->IniData.TimerInterval ;
  675.   Data->MonitorParms.Priority = & Data->IniData.MonitorPriority ;
  676.   Data->MonitorParms.Owner = hwnd ;
  677.   Data->MonitorTID = StartThread ( "MonitorLoopThread", MonitorLoopThread, 0x3000, &Data->MonitorParms ) ;
  678.  
  679.  /***************************************************************************
  680.   * Add the program to the system task list.                                *
  681.   ***************************************************************************/
  682.  
  683.   ResourceString Title ( Data->Library->QueryHandle(), IDS_TITLE ) ;
  684.   Add2TaskList ( Frame, PSZ(Title) ) ;
  685.  
  686.  /***************************************************************************
  687.   * Hide the controls if so configured.                                     *
  688.   ***************************************************************************/
  689.  
  690.   #ifdef DEBUG
  691.   Log ( "Create: HideControls:%s, Minimize:%s.",
  692.      Data->IniData.HideControls ? "TRUE" : "FALSE",
  693.      Data->IniData.Position.fl & SWP_MINIMIZE ? "TRUE" : "FALSE" ) ;
  694.   #endif
  695.  
  696.   if ( Data->IniData.HideControls AND NOT ( Data->IniData.Position.fl & SWP_MINIMIZE ) ) {
  697.      #ifdef DEBUG
  698.      Log ( "Create: Hiding controls." ) ;
  699.      #endif
  700.      HideControls ( TRUE, Frame, Data->SysMenu, Data->TitleBar, Data->MinMax ) ;
  701.   } /* endif */
  702.  
  703.  /***************************************************************************
  704.   * Position & size the window.  For some reason, we must move and size     *
  705.   *   the window to the saved position before applying the resizing         *
  706.   *   function as fine-tuning.  Maybe the positioning request fails if      *
  707.   *   the window has no size?                                               *
  708.   ***************************************************************************/
  709.  
  710.   #ifdef DEBUG
  711.   Log ( "Create: Setting window position to %i,%i (%ix%i).",
  712.      Data->IniData.Position.x, Data->IniData.Position.y,
  713.      Data->IniData.Position.cx, Data->IniData.Position.cy ) ;
  714.   #endif
  715.  
  716.   WinSetWindowPos ( Frame, HWND_BOTTOM,
  717.      Data->IniData.Position.x, Data->IniData.Position.y,
  718.      Data->IniData.Position.cx, Data->IniData.Position.cy,
  719.      SWP_SIZE | SWP_MOVE | SWP_ZORDER |
  720.      ( Data->IniData.Position.fl & SWP_MINIMIZE ) |
  721.      ( Data->IniData.Position.fl & SWP_RESTORE ) ) ;
  722.  
  723.  /***************************************************************************
  724.   * Adjust the window size to suit the displayable items.                   *
  725.   ***************************************************************************/
  726.  
  727.   ResizeWindow ( hwnd ) ;
  728.  
  729.  /***************************************************************************
  730.   * Determine our font size.                                                *
  731.   ***************************************************************************/
  732.  
  733.   HPS hPS = WinGetPS ( hwnd ) ;
  734.   RECTL Rectangle ;
  735.   WinQueryWindowRect ( HWND_DESKTOP, &Rectangle ) ;
  736.   WinDrawText ( hPS, 1, PSZ(" "), &Rectangle, 0, 0, DT_LEFT | DT_BOTTOM | DT_QUERYEXTENT ) ;
  737.   Data->Width  = Rectangle.xRight - Rectangle.xLeft ;
  738.   Data->Height = Rectangle.yTop - Rectangle.yBottom ;
  739.   WinReleasePS ( hPS ) ;
  740.  
  741.  /***************************************************************************
  742.   * Now that the window's in order, make it visible.                        *
  743.   ***************************************************************************/
  744.  
  745.   WinShowWindow ( Frame, TRUE ) ;
  746.  
  747.  /***************************************************************************
  748.   * Success?  Return no error.                                              *
  749.   ***************************************************************************/
  750.  
  751.   return ( 0 ) ;
  752. }
  753.  
  754. /****************************************************************************
  755.  *                                                                          *
  756.  *      Destroy main window.                                                *
  757.  *                                                                          *
  758.  ****************************************************************************/
  759.  
  760. STATIC MRESULT APIENTRY Destroy ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  761.  
  762.  /***************************************************************************
  763.   * Find the instance data.                                                 *
  764.   ***************************************************************************/
  765.  
  766.   PDATA Data = PDATA ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  767.  
  768.  /***************************************************************************
  769.   * Kill the extra threads.                                                 *
  770.   ***************************************************************************/
  771.  
  772.   DosResumeThread ( Data->MonitorTID ) ;
  773.   Data->MonitorParms.Active = FALSE ;
  774.   MonitorThreadEvent.Wait ( 10000 ) ;
  775.  
  776.   DosResumeThread ( Data->CounterTID ) ;
  777.   Data->CounterParms.Active = FALSE ;
  778.   DosSetPriority ( PRTYS_THREAD, PRTYC_TIMECRITICAL, PRTYD_MAXIMUM, Data->CounterTID ) ;
  779.   CounterThreadEvent.Wait ( 10000 ) ;
  780.  
  781.  /***************************************************************************
  782.   * Destroy the DDE Server object.                                          *
  783.   ***************************************************************************/
  784.  
  785.   delete Data->pDdeServer ;
  786.  
  787.  /***************************************************************************
  788.   * Release the instance memory.                                            *
  789.   ***************************************************************************/
  790.  
  791.   free ( Data ) ;
  792.  
  793.  /***************************************************************************
  794.   * We're done.                                                             *
  795.   ***************************************************************************/
  796.  
  797.   return ( MRFROMSHORT ( 0 ) ) ;
  798. }
  799.  
  800. /****************************************************************************
  801.  *                                                                          *
  802.  *      Process window resize message.                                      *
  803.  *                                                                          *
  804.  ****************************************************************************/
  805.  
  806. STATIC MRESULT APIENTRY Size ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  807.  
  808.   #ifdef DEBUG
  809.   Log ( "Size: Started." ) ;
  810.   #endif
  811.  
  812.  /***************************************************************************
  813.   * Find the instance data.                                                 *
  814.   ***************************************************************************/
  815.  
  816.   PDATA Data = PDATA ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  817.  
  818.  /***************************************************************************
  819.   * Find out the window's new position and size.                            *
  820.   ***************************************************************************/
  821.  
  822.   HWND Frame = WinQueryWindow ( hwnd, QW_PARENT ) ;
  823.  
  824.   SWP Position ;
  825.   WinQueryWindowPos ( Frame, &Position ) ;
  826.  
  827.   if (   NOT ( Position.fl & SWP_HIDE     )
  828.      AND NOT ( Position.fl & SWP_MINIMIZE )
  829.      AND NOT ( Position.fl & SWP_MAXIMIZE ) ) {
  830.  
  831.      Data->IniData.Position.x = Position.x ;
  832.      Data->IniData.Position.y = Position.y ;
  833.  
  834.      Data->IniData.Position.cx = Position.cx ;
  835.      Data->IniData.Position.cy = Position.cy ;
  836.  
  837.      #ifdef DEBUG
  838.      Log ( "Size: Window position set to %i,%i (%ix%i).",
  839.         Data->IniData.Position.x, Data->IniData.Position.y,
  840.         Data->IniData.Position.cx, Data->IniData.Position.cy ) ;
  841.      #endif
  842.  
  843.   } /* endif */
  844.  
  845.  /***************************************************************************
  846.   * If hiding the controls . . .                                            *
  847.   ***************************************************************************/
  848.  
  849.   if ( Data->IniData.HideControls ) {
  850.  
  851.    /*************************************************************************
  852.     * If changing to or from minimized state . . .                          *
  853.     *************************************************************************/
  854.  
  855.     if ( ( Position.fl & SWP_MINIMIZE ) != ( Data->IniData.Position.fl & SWP_MINIMIZE ) ) {
  856.  
  857.      /***********************************************************************
  858.       * Hide the controls if no longer minimized.                           *
  859.       ***********************************************************************/
  860.  
  861.       HideControls ( NOT ( Position.fl & SWP_MINIMIZE ),
  862.         Frame, Data->SysMenu, Data->TitleBar, Data->MinMax ) ;
  863.  
  864.     }
  865.   }
  866.  
  867.   Data->IniData.Position.fl = Position.fl ;
  868.  
  869.  /***************************************************************************
  870.   * We're done.                                                             *
  871.   ***************************************************************************/
  872.  
  873.   #ifdef DEBUG
  874.   Log ( "Size: Done." ) ;
  875.   #endif
  876.  
  877.   return ( 0 ) ;
  878. }
  879.  
  880. /****************************************************************************
  881.  *                                                                          *
  882.  *      Process SAVE APPLICATION message.                                   *
  883.  *                                                                          *
  884.  ****************************************************************************/
  885.  
  886. STATIC MRESULT APIENTRY SaveApplication ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  887.  
  888.  /***************************************************************************
  889.   * Find the instance data.                                                 *
  890.   ***************************************************************************/
  891.  
  892.   PDATA Data = PDATA ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  893.  
  894.  /***************************************************************************
  895.   * Call function to put all profile data out to the system.                *
  896.   ***************************************************************************/
  897.  
  898.   PutIniData ( Data->IniFile->QueryHandle(), &Data->IniData ) ;
  899.  
  900.  /***************************************************************************
  901.   * We're done.  Let the system complete default processing.                *
  902.   ***************************************************************************/
  903.  
  904.   return ( WinDefWindowProc ( hwnd, WM_SAVEAPPLICATION, 0, 0 ) ) ;
  905. }
  906.  
  907. /****************************************************************************
  908.  *                                                                          *
  909.  *      Repaint entire window.                                              *
  910.  *                                                                          *
  911.  ****************************************************************************/
  912.  
  913. STATIC MRESULT APIENTRY Paint ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  914.  
  915.  /***************************************************************************
  916.   * Find the instance data.                                                 *
  917.   ***************************************************************************/
  918.  
  919.   PDATA Data = PDATA ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  920.  
  921.  /***************************************************************************
  922.   * Get presentation space and make it use RGB colors.                      *
  923.   ***************************************************************************/
  924.  
  925.   HPS hPS = WinBeginPaint ( hwnd, 0, 0 ) ;
  926.   GpiCreateLogColorTable ( hPS, LCOL_RESET, LCOLF_RGB, 0, 0, 0 ) ;
  927.  
  928.  /***************************************************************************
  929.   * Get font information for later use with Copy command.                   *
  930.   ***************************************************************************/
  931.  
  932.   GpiQueryFontMetrics ( hPS, sizeof(Data->FontMetrics), &Data->FontMetrics ) ;
  933.   Data->CharMode = GpiQueryCharMode ( hPS ) ;
  934.   GpiQueryCharBox ( hPS, &Data->CharBox ) ;
  935.  
  936.  /***************************************************************************
  937.   * Clear the window.                                                       *
  938.   ***************************************************************************/
  939.  
  940.   RECTL Rectangle ;
  941.   WinQueryWindowRect ( hwnd, &Rectangle ) ;
  942.  
  943.   GpiMove ( hPS, (PPOINTL) &Rectangle.xLeft ) ;
  944.   GpiSetColor ( hPS, Data->IniData.BackColor ) ;
  945.   GpiBox ( hPS, DRO_FILL, (PPOINTL) &Rectangle.xRight, 0, 0 ) ;
  946.  
  947.  /***************************************************************************
  948.   * Release presentation space.                                             *
  949.   ***************************************************************************/
  950.  
  951.   WinEndPaint ( hPS ) ;
  952.  
  953.  /***************************************************************************
  954.   * Update the window and return.                                           *
  955.   ***************************************************************************/
  956.  
  957.   UpdateWindow ( hwnd, Data, TRUE ) ;
  958.  
  959.   return ( 0 ) ;
  960. }
  961.  
  962. /****************************************************************************
  963.  *                                                                          *
  964.  *      Process requests for menu initialization.                           *
  965.  *                                                                          *
  966.  ****************************************************************************/
  967.  
  968. static MRESULT APIENTRY InitMenu ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  969.  
  970.  /***************************************************************************
  971.   * Find the instance data.                                                 *
  972.   ***************************************************************************/
  973.  
  974.   PDATA Data = PDATA ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  975.  
  976.  /***************************************************************************
  977.   * Get the message data.                                                   *
  978.   ***************************************************************************/
  979.  
  980.   int MenuID = SHORT1FROMMP ( mp1 ) ;
  981.   HWND Menu = HWNDFROMMP ( mp2 ) ;
  982.  
  983.  /***************************************************************************
  984.   * Process according to which menu's about to be displayed.                *
  985.   ***************************************************************************/
  986.  
  987.   switch ( MenuID ) {
  988.  
  989.      case FID_SYSMENU:
  990.      case FID_MENU:
  991.      case IDM_MENU: {
  992.         CheckMenuItem ( Menu, IDM_HIDE_CONTROLS, Data->IniData.HideControls ) ;
  993.         break ; }
  994.  
  995.   }
  996.  
  997.  /***************************************************************************
  998.   * We're done.                                                             *
  999.   ***************************************************************************/
  1000.  
  1001.   return ( MRFROMSHORT ( 0 ) ) ;
  1002. }
  1003.  
  1004. /****************************************************************************
  1005.  *                                                                          *
  1006.  *      Process commands received by Main Window                            *
  1007.  *                                                                          *
  1008.  ****************************************************************************/
  1009.  
  1010. STATIC MRESULT APIENTRY Command ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  1011.  
  1012.  /***************************************************************************
  1013.   * Dispatch all other commands through the method table.                   *
  1014.   ***************************************************************************/
  1015.  
  1016.   static METHOD Methods [] = {
  1017.     { IDM_SAVE_APPLICATION, SaveApplication },
  1018.     { IDM_RESET_DEFAULTS,   ResetDefaults   },
  1019.     { IDM_HIDE_CONTROLS,    HideControlsCmd },
  1020.     { IDM_CONFIGURE,        Configure       },
  1021.     { IDM_RESETLOAD,        ResetLoad       },
  1022.     { IDM_COPY,             Copy            },
  1023.     { IDM_EXIT,             Exit            },
  1024.     { IDM_ABOUT,            About           },
  1025.   } ;
  1026.  
  1027.   return ( DispatchMessage ( hwnd, SHORT1FROMMP(mp1), mp1, mp2, Methods, sizeof(Methods)/sizeof(Methods[0]), 0 ) ) ;
  1028. }
  1029.  
  1030. /****************************************************************************
  1031.  *                                                                          *
  1032.  *      Process Reset Defaults menu command.                                *
  1033.  *                                                                          *
  1034.  ****************************************************************************/
  1035.  
  1036. STATIC MRESULT APIENTRY ResetDefaults ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  1037.  
  1038.  /***************************************************************************
  1039.   * Find the instance data.                                                 *
  1040.   ***************************************************************************/
  1041.  
  1042.   PDATA Data = PDATA ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  1043.  
  1044.  /***************************************************************************
  1045.   * Reset all profile data for this program.                                *
  1046.   ***************************************************************************/
  1047.  
  1048.   PrfWriteProfileData ( Data->IniFile->QueryHandle(), PSZ(PROGRAM_NAME), 0, 0, 0 ) ;
  1049.  
  1050.  /***************************************************************************
  1051.   * Reset the program's presentation parameters.                            *
  1052.   ***************************************************************************/
  1053.  
  1054.   WinRemovePresParam ( hwnd, PP_FONTNAMESIZE ) ;
  1055.   WinRemovePresParam ( hwnd, PP_FOREGROUNDCOLOR ) ;
  1056.   WinRemovePresParam ( hwnd, PP_BACKGROUNDCOLOR ) ;
  1057.  
  1058.  /***************************************************************************
  1059.   * Done.                                                                   *
  1060.   ***************************************************************************/
  1061.  
  1062.   return ( MRFROMSHORT ( 0 ) ) ;
  1063. }
  1064.  
  1065. /****************************************************************************
  1066.  *                                                                          *
  1067.  *      Process Hide Controls menu command.                                 *
  1068.  *                                                                          *
  1069.  ******************m*********************************************************/
  1070.  
  1071. STATIC MRESULT APIENTRY HideControlsCmd ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  1072.  
  1073.  /***************************************************************************
  1074.   * Find the instance data.                                                 *
  1075.   ***************************************************************************/
  1076.  
  1077.   PDATA Data = PDATA ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  1078.  
  1079.  /***************************************************************************
  1080.   * Toggle the Hide Controls setting.                                       *
  1081.   ***************************************************************************/
  1082.  
  1083.   Data->IniData.HideControls = Data->IniData.HideControls ? FALSE : TRUE ;
  1084.   Data->IniData.fHideControls = TRUE ;
  1085.  
  1086.  /***************************************************************************
  1087.   * Get the frame handle.                                                   *
  1088.   ***************************************************************************/
  1089.  
  1090.   HWND Frame = WinQueryWindow ( hwnd, QW_PARENT ) ;
  1091.  
  1092.  /***************************************************************************
  1093.   * If not minimized right now, hide or reveal the controls.                *
  1094.   ***************************************************************************/
  1095.  
  1096.   if ( NOT ( Data->IniData.Position.fl & SWP_MINIMIZE ) ) {
  1097.     HideControls ( Data->IniData.HideControls,
  1098.       Frame, Data->SysMenu, Data->TitleBar, Data->MinMax ) ;
  1099.   }
  1100.  
  1101.  /***************************************************************************
  1102.   * Done.                                                                   *
  1103.   ***************************************************************************/
  1104.  
  1105.   return ( MRFROMSHORT ( 0 ) ) ;
  1106. }
  1107.  
  1108. /****************************************************************************
  1109.  *                                                                          *
  1110.  *      Process Configure command.                                          *
  1111.  *                                                                          *
  1112.  ****************************************************************************/
  1113.  
  1114. STATIC MRESULT APIENTRY Configure ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  1115.  
  1116.  /***************************************************************************
  1117.   * Find the instance data.                                                 *
  1118.   ***************************************************************************/
  1119.  
  1120.   PDATA Data = PDATA ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  1121.  
  1122.  /***************************************************************************
  1123.   * Invoke the Configure dialog.  If cancelled, just return.                *
  1124.   ***************************************************************************/
  1125.  
  1126.   CONFIG_PARMS Parms ;
  1127.   Parms.HideControls        = Data->IniData.HideControls ;
  1128.   Parms.Float               = Data->IniData.Float ;
  1129.   Parms.Animate             = Data->IniData.Animate ;
  1130.   Parms.ShowFileSystemNames = Data->IniData.ShowFileSystemNames ;
  1131.   Parms.ShowDiskLabels      = Data->IniData.ShowDiskLabels ;
  1132.   Parms.ShowSeconds         = Data->IniData.ShowSeconds ;
  1133.   Parms.ShowK               = Data->IniData.ShowK ;
  1134.   Parms.MonitorPriority     = Data->IniData.MonitorPriority ;
  1135.   Parms.TimerInterval       = Data->IniData.TimerInterval ;
  1136.   Parms.AnchorCorner        = Data->IniData.AnchorCorner ;
  1137.   Parms.ItemCount           = Data->IniData.ItemCount ;
  1138.  
  1139.   for ( int i=0; i<Data->IniData.ItemCount; i++ ) {
  1140.      Item *pItem = Data->IniData.Items[i].pItem ;
  1141.      Parms.ItemFlags[i] = pItem->QueryFlag () ;
  1142.      strcpy ( Parms.CurrentLabels[i], PCHAR(pItem->QueryCurrentLabel()) ) ;
  1143.      strcpy ( Parms.DefaultLabels[i], PCHAR(pItem->QueryDefaultLabel()) ) ;
  1144.   } /* endfor */
  1145.  
  1146.   if ( WinDlgBox ( HWND_DESKTOP, hwnd, PFNWP(ConfigureProcessor),
  1147.      Data->Library->QueryHandle(), IDD_CONFIGURE, &Parms ) == FALSE )
  1148.   {
  1149.      return ( MRFROMSHORT ( 0 ) ) ;
  1150.   }
  1151.  
  1152.  /***************************************************************************
  1153.   * Save the new monitor priority.                                          *
  1154.   ***************************************************************************/
  1155.  
  1156.   Data->IniData.fMonitorPriority = TRUE ;
  1157.   Data->IniData.MonitorPriority = BYTE ( Parms.MonitorPriority ) ;
  1158.  
  1159.  /***************************************************************************
  1160.   * Save the new timer interval.                                            *
  1161.   ***************************************************************************/
  1162.  
  1163.   Data->IniData.fTimerInterval = TRUE ;
  1164.   Data->IniData.TimerInterval = USHORT ( Parms.TimerInterval ) ;
  1165.  
  1166.  /***************************************************************************
  1167.   * Save the float-to-top flag.                                             *
  1168.   ***************************************************************************/
  1169.  
  1170.   Data->IniData.fFloat = TRUE ;
  1171.   Data->IniData.Float = Parms.Float ;
  1172.  
  1173.  /***************************************************************************
  1174.   * Save the window animate flag.                                           *
  1175.   ***************************************************************************/
  1176.  
  1177.   Data->IniData.fAnimate = TRUE ;
  1178.   Data->IniData.Animate = Parms.Animate ;
  1179.  
  1180.  /***************************************************************************
  1181.   * Save the anchor corner flag.                                            *
  1182.   ***************************************************************************/
  1183.  
  1184.   Data->IniData.fAnchorCorner = TRUE ;
  1185.   Data->IniData.AnchorCorner = Parms.AnchorCorner ;
  1186.  
  1187.  /***************************************************************************
  1188.   * Save the hide controls flag, and adjust the window if it changed.       *
  1189.   ***************************************************************************/
  1190.  
  1191.   Data->IniData.fHideControls = TRUE ;
  1192.   if ( Data->IniData.HideControls != Parms.HideControls ) {
  1193.      HWND FrameWindow = WinQueryWindow ( hwnd, QW_PARENT ) ;
  1194.      Data->IniData.HideControls = Parms.HideControls ;
  1195.      if ( NOT ( Data->IniData.Position.fl & SWP_MINIMIZE ) )
  1196.         HideControls ( Data->IniData.HideControls, FrameWindow, Data->SysMenu, Data->TitleBar, Data->MinMax ) ;
  1197.   } /* endif */
  1198.  
  1199.  /***************************************************************************
  1200.   * If CPU load monitoring has changed, start/stop the monitoring thread.   *
  1201.   ***************************************************************************/
  1202.  
  1203.   if ( Parms.ItemFlags[ITEM_CPULOAD] != Data->IniData.Items[ITEM_CPULOAD].pItem->QueryFlag() )
  1204.      if ( Parms.ItemFlags[ITEM_CPULOAD] )
  1205.         DosResumeThread ( Data->CounterTID ) ;
  1206.      else
  1207.         DosSuspendThread ( Data->CounterTID ) ;
  1208.  
  1209.  /***************************************************************************
  1210.   * Determine if the display item list has changed.  If not, return.        *
  1211.   ***************************************************************************/
  1212.  
  1213.   BOOL ItemsChanged = FALSE ;
  1214.   for ( i=0; i<Data->IniData.ItemCount; i++ ) {
  1215.      Item *pItem = Data->IniData.Items[i].pItem ;
  1216.      if ( Parms.ItemFlags[i] != pItem->QueryFlag() ) {
  1217.         ItemsChanged = TRUE ;
  1218.         break ;
  1219.      } /* endif */
  1220.      if ( strcmp ( Parms.CurrentLabels[i], PCHAR(pItem->QueryCurrentLabel()) ) ) {
  1221.         ItemsChanged = TRUE ;
  1222.         break ;
  1223.      } /* endif */
  1224.   } /* endfor */
  1225.  
  1226.   if ( NOT ItemsChanged
  1227.      AND ( Data->IniData.ShowFileSystemNames == Parms.ShowFileSystemNames )
  1228.      AND ( Data->IniData.ShowDiskLabels == Parms.ShowDiskLabels )
  1229.      AND ( Data->IniData.ShowSeconds == Parms.ShowSeconds )
  1230.      AND ( Data->IniData.ShowK == Parms.ShowK ) ) {
  1231.      return ( MRFROMSHORT ( 0 ) ) ;
  1232.   } /* endif */
  1233.  
  1234.  /***************************************************************************
  1235.   * Save the show file-system names flag.                                   *
  1236.   ***************************************************************************/
  1237.  
  1238.   Data->IniData.fShowFileSystemNames = TRUE ;
  1239.   Data->IniData.ShowFileSystemNames = Parms.ShowFileSystemNames ;
  1240.  
  1241.   for ( i=ITEM_BASE_COUNT; i<Data->IniData.ItemCount; i++ ) {
  1242.      Item *pItem = Data->IniData.Items[i].pItem ;
  1243.      ((DriveFree*)pItem)->SetShowFileSystemName ( Data->IniData.ShowFileSystemNames ) ;
  1244.   } /* endfor */
  1245.  
  1246.  /***************************************************************************
  1247.   * Save the show disk labels flag.                                         *
  1248.   ***************************************************************************/
  1249.  
  1250.   Data->IniData.fShowDiskLabels = TRUE ;
  1251.   Data->IniData.ShowDiskLabels = Parms.ShowDiskLabels ;
  1252.  
  1253.   for ( i=ITEM_BASE_COUNT; i<Data->IniData.ItemCount; i++ ) {
  1254.      Item *pItem = Data->IniData.Items[i].pItem ;
  1255.      ((DriveFree*)pItem)->SetShowDiskLabel ( Data->IniData.ShowDiskLabels ) ;
  1256.   } /* endfor */
  1257.  
  1258.  /***************************************************************************
  1259.   * Save the show seconds flag.                                             *
  1260.   ***************************************************************************/
  1261.  
  1262.   Data->IniData.fShowSeconds = TRUE ;
  1263.   Data->IniData.ShowSeconds = Parms.ShowSeconds ;
  1264.  
  1265.   ((Clock*)Data->IniData.Items[ITEM_CLOCK].pItem)->SetShowSeconds ( Data->IniData.ShowSeconds ) ;
  1266.   ((ElapsedTime*)Data->IniData.Items[ITEM_ELAPSEDTIME].pItem)->SetShowSeconds ( Data->IniData.ShowSeconds ) ;
  1267.  
  1268.  /***************************************************************************
  1269.   * Save the show 'K' flag.                                                 *
  1270.   ***************************************************************************/
  1271.  
  1272.   Data->IniData.fShowK = TRUE ;
  1273.   Data->IniData.ShowK = Parms.ShowK ;
  1274.  
  1275.   ((MemoryFree *)Data->IniData.Items[ITEM_MEMORYFREE   ].pItem)->SetShowK ( Data->IniData.ShowK ) ;
  1276.   ((VirtualFree*)Data->IniData.Items[ITEM_VIRTUALFREE  ].pItem)->SetShowK ( Data->IniData.ShowK ) ;
  1277.   ((SwapFree   *)Data->IniData.Items[ITEM_SWAPDISKFREE ].pItem)->SetShowK ( Data->IniData.ShowK ) ;
  1278.   ((SwapSize   *)Data->IniData.Items[ITEM_SWAPFILESIZE ].pItem)->SetShowK ( Data->IniData.ShowK ) ;
  1279.   ((SwapSlack  *)Data->IniData.Items[ITEM_SWAPFILESLACK].pItem)->SetShowK ( Data->IniData.ShowK ) ;
  1280.   ((SpoolSize  *)Data->IniData.Items[ITEM_SPOOLFILESIZE].pItem)->SetShowK ( Data->IniData.ShowK ) ;
  1281.   ((TotalFree  *)Data->IniData.Items[ITEM_TOTALFREE    ].pItem)->SetShowK ( Data->IniData.ShowK ) ;
  1282.  
  1283.   for ( i=ITEM_BASE_COUNT; i<Data->IniData.ItemCount; i++ ) {
  1284.      Item *pItem = Data->IniData.Items[i].pItem ;
  1285.      ((DriveFree*)pItem)->SetShowK ( Data->IniData.ShowK ) ;
  1286.   } /* endfor */
  1287.  
  1288.  /***************************************************************************
  1289.   * Save the new item flags.                                                *
  1290.   ***************************************************************************/
  1291.  
  1292.   for ( i=0; i<Data->IniData.ItemCount; i++ ) {
  1293.      Item *pItem = Data->IniData.Items[i].pItem ;
  1294.      if ( Parms.ItemFlags[i] )
  1295.         pItem->SetFlag ( ) ;
  1296.      else
  1297.         pItem->ResetFlag ( ) ;
  1298.      pItem->SetLabel ( Parms.CurrentLabels[i] ) ;
  1299.   } /* endif */
  1300.  
  1301.  /***************************************************************************
  1302.   * Resize the display window.                                              *
  1303.   ***************************************************************************/
  1304.  
  1305.   ResizeWindow ( hwnd ) ;
  1306.  
  1307.  /***************************************************************************
  1308.   * Done.                                                                   *
  1309.   ***************************************************************************/
  1310.  
  1311.   return ( MRFROMSHORT ( 0 ) ) ;
  1312. }
  1313.  
  1314. /****************************************************************************
  1315.  *                                                                          *
  1316.  *      Process Reset Load menu command.                                    *
  1317.  *                                                                          *
  1318.  ****************************************************************************/
  1319.  
  1320. STATIC MRESULT APIENTRY ResetLoad ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  1321.  
  1322.  /***************************************************************************
  1323.   * Find the instance data.                                                 *
  1324.   ***************************************************************************/
  1325.  
  1326.   PDATA Data = PDATA ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  1327.  
  1328.  /***************************************************************************
  1329.   * Shut down the CPU load meter threads.                                   *
  1330.   ***************************************************************************/
  1331.  
  1332.   DosResumeThread ( Data->MonitorTID ) ;
  1333.   Data->MonitorParms.Active = FALSE ;
  1334.   MonitorThreadEvent.Wait ( 10000 ) ;
  1335.  
  1336.   DosResumeThread ( Data->CounterTID ) ;
  1337.   Data->CounterParms.Active = FALSE ;
  1338.   DosSetPriority ( PRTYS_THREAD, PRTYC_TIMECRITICAL, PRTYD_MAXIMUM, Data->CounterTID ) ;
  1339.   CounterThreadEvent.Wait ( 10000 ) ;
  1340.  
  1341.  /***************************************************************************
  1342.   * Reset the load meter.                                                   *
  1343.   ***************************************************************************/
  1344.  
  1345.   Data->IniData.MaxCount = CalibrateLoadMeter ( &Data->CounterParms ) ;
  1346.   Data->IniData.MaxCount = (ULONG) max ( 1, Data->IniData.MaxCount ) ;
  1347.  
  1348.  /***************************************************************************
  1349.   * Restart the CPU load meter threads.                                     *
  1350.   ***************************************************************************/
  1351.  
  1352.   CounterThreadEvent.Reset ( ) ;
  1353.   Data->CounterParms.Active = TRUE ;
  1354.   Data->CounterTID = StartThread ( "CounterThread", CounterThread, 0x3000, &Data->CounterParms ) ;
  1355.   DosSuspendThread ( Data->CounterTID ) ;
  1356.   DosSetPriority ( PRTYS_THREAD, PRTYC_IDLETIME, PRTYD_MINIMUM, Data->CounterTID ) ;
  1357.  
  1358.   Data->IniData.IdleCount = 0 ;
  1359.   Data->CounterParms.Counter = 0 ;
  1360.  
  1361.   if ( Data->IniData.Items[ITEM_CPULOAD].pItem->QueryFlag() )
  1362.      DosResumeThread ( Data->CounterTID ) ;
  1363.  
  1364.   MonitorThreadEvent.Reset ( ) ;
  1365.   Data->MonitorParms.Active = TRUE ;
  1366.   Data->MonitorParms.Counter = & Data->CounterParms.Counter ;
  1367.   Data->MonitorParms.Interval = & Data->IniData.TimerInterval ;
  1368.   Data->MonitorParms.Priority = & Data->IniData.MonitorPriority ;
  1369.   Data->MonitorParms.Owner = hwnd ;
  1370.   Data->MonitorTID = StartThread ( "MonitorLoopThread", MonitorLoopThread, 0x3000, &Data->MonitorParms ) ;
  1371.  
  1372.  /***************************************************************************
  1373.   * Done.                                                                   *
  1374.   ***************************************************************************/
  1375.  
  1376.   return ( MRFROMSHORT ( 0 ) ) ;
  1377. }
  1378.  
  1379. /****************************************************************************
  1380.  *                                                                          *
  1381.  *      Process Copy command.                                               *
  1382.  *                                                                          *
  1383.  ****************************************************************************/
  1384.  
  1385. STATIC MRESULT APIENTRY Copy ( HWND Window, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  1386.  
  1387.   /**************************************************************************
  1388.    * Find the instance data.                                                *
  1389.    **************************************************************************/
  1390.  
  1391.    PDATA Data = PDATA ( WinQueryWindowPtr ( Window, QWL_USER ) ) ;
  1392.  
  1393.   /**************************************************************************
  1394.    * Review all items.  Display those changed, or all.                      *
  1395.    **************************************************************************/
  1396.  
  1397.    char *Buffer = (char*) malloc ( ( ITEM_BASE_COUNT + MAX_DRIVES ) * ( Data->MaxColumns + 1 ) ) ;
  1398.    Buffer [0] = 0 ;
  1399.  
  1400.    for ( int i=0; i<Data->IniData.ItemCount; i++ ) {
  1401.       Item *pItem = Data->IniData.Items[i].pItem ;
  1402.       if ( pItem->QueryFlag() ) {
  1403.          pItem->FormatLine ( Buffer, Data->MaxColumns ) ;
  1404.       } /* endif */
  1405.    } /* endfor */
  1406.  
  1407.    char *ClipText ;
  1408.    DosAllocSharedMem ( PPVOID(&ClipText), 0, strlen(Buffer)+1,
  1409.       PAG_WRITE | PAG_COMMIT | OBJ_GIVEABLE ) ;
  1410.    strcpy ( ClipText, Buffer ) ;
  1411.    free ( Buffer ) ;
  1412.  
  1413.   /**************************************************************************
  1414.    * Create bitmap image of current window.                                 *
  1415.    **************************************************************************/
  1416.  
  1417.    static PSZ pszData [2] = { 0, PSZ("Display") } ;
  1418.    HDC MemoryDC = DevOpenDC ( Data->Proc->QueryAnchor(), OD_MEMORY, PSZ("*"), 2, PDEVOPENDATA(pszData), 0 ) ;
  1419.  
  1420.    SIZEL PageSize = { 0, 0 } ;
  1421.    HPS hPS = GpiCreatePS ( Data->Proc->QueryAnchor(), MemoryDC, &PageSize, PU_PELS | GPIA_ASSOC | GPIT_MICRO ) ;
  1422.    GpiCreateLogColorTable ( hPS, LCOL_RESET, LCOLF_RGB, 0, 0, 0 ) ;
  1423.  
  1424.    LONG alData [2] ;
  1425.    GpiQueryDeviceBitmapFormats ( hPS, 2, alData ) ;
  1426.  
  1427.    RECTL Rectangle ;
  1428.    WinQueryWindowRect ( Window, &Rectangle ) ;
  1429.  
  1430.    BITMAPINFOHEADER2 BitmapHeader ;
  1431.    memset ( &BitmapHeader, 0, sizeof(BitmapHeader) ) ;
  1432.    BitmapHeader.cbFix = 16 ;
  1433.    BitmapHeader.cx = Rectangle.xRight - Rectangle.xLeft ;
  1434.    BitmapHeader.cy = Rectangle.yTop - Rectangle.yBottom ;
  1435.    BitmapHeader.cPlanes = USHORT ( alData[0] ) ;
  1436.    BitmapHeader.cBitCount = USHORT ( alData[1] ) ;
  1437.  
  1438.    HBITMAP Bitmap = GpiCreateBitmap ( hPS, &BitmapHeader, 0, 0, 0 ) ;
  1439.    GpiSetBitmap ( hPS, Bitmap ) ;
  1440.  
  1441.    FATTRS FontAttributes ;
  1442.    memset ( &FontAttributes, 0, sizeof(FontAttributes) ) ;
  1443.    strcpy ( FontAttributes.szFacename, Data->FontMetrics.szFacename ) ;
  1444.    FontAttributes.usRecordLength  = sizeof(FontAttributes) ;
  1445.    FontAttributes.usCodePage      = Data->FontMetrics.usCodePage ;
  1446.    FontAttributes.lMaxBaselineExt = Data->FontMetrics.lMaxBaselineExt ;
  1447.    FontAttributes.lAveCharWidth   = Data->FontMetrics.lAveCharWidth ;
  1448.  
  1449.    GpiCreateLogFont ( hPS, 0, 1, &FontAttributes ) ;
  1450.    GpiSetCharSet ( hPS, 1 ) ;
  1451.    GpiSetCharMode ( hPS, Data->CharMode ) ;
  1452.    if ( Data->CharMode == CM_MODE3 )
  1453.       GpiSetCharBox ( hPS, &Data->CharBox ) ;
  1454.  
  1455.    GpiMove ( hPS, PPOINTL(&Rectangle.xLeft) ) ;
  1456.    GpiSetColor ( hPS, Data->IniData.BackColor ) ;
  1457.    GpiBox ( hPS, DRO_FILL, PPOINTL(&Rectangle.xRight), 0, 0 ) ;
  1458.  
  1459.    int Count = 0 ;
  1460.    for ( i=0; i<Data->IniData.ItemCount; i++ ) {
  1461.       Item *pItem = Data->IniData.Items[i].pItem ;
  1462.       if ( pItem->QueryFlag() ) {
  1463.          Count ++ ;
  1464.       } /* endif */
  1465.    } /* endfor */
  1466.  
  1467.    Rectangle.xLeft += Data->Width / 2 ;
  1468.    Rectangle.xRight -= Data->Width / 2 ;
  1469.  
  1470.    Rectangle.yBottom = Data->Height * ( Count - 1 ) ;
  1471.    Rectangle.yTop = Rectangle.yBottom + Data->Height ;
  1472.  
  1473.    for ( i=0; i<Data->IniData.ItemCount; i++ ) {
  1474.       Item *pItem = Data->IniData.Items[i].pItem ;
  1475.       if ( pItem->QueryFlag() ) {
  1476.          pItem->Repaint ( hPS, Rectangle, Data->IniData.TextColor, Data->IniData.BackColor, TRUE ) ;
  1477.          Rectangle.yBottom -= Data->Height ;
  1478.          Rectangle.yTop    -= Data->Height ;
  1479.       } /* endif */
  1480.    } /* endfor */
  1481.  
  1482.    GpiDestroyPS ( hPS ) ;
  1483.    DevCloseDC ( MemoryDC ) ;
  1484.  
  1485.   /**************************************************************************
  1486.    * Empty the clipboard and give it new data.                              *
  1487.    **************************************************************************/
  1488.  
  1489.    if ( WinOpenClipbrd ( Data->Proc->QueryAnchor() ) ) {
  1490.       WinEmptyClipbrd ( Data->Proc->QueryAnchor() ) ;
  1491.       WinSetClipbrdData ( Data->Proc->QueryAnchor(), ULONG(ClipText), CF_TEXT, CFI_POINTER ) ;
  1492.       WinSetClipbrdData ( Data->Proc->QueryAnchor(), ULONG(Bitmap), CF_BITMAP, CFI_HANDLE ) ;
  1493.       WinCloseClipbrd ( Data->Proc->QueryAnchor() ) ;
  1494.    } else {
  1495.       DosFreeMem ( ClipText ) ;
  1496.    } /* endif */
  1497.  
  1498.   /**************************************************************************
  1499.    * Done.                                                                  *
  1500.    **************************************************************************/
  1501.  
  1502.    return ( MRFROMSHORT ( 0 ) ) ;
  1503. }
  1504.  
  1505. /****************************************************************************
  1506.  *                                                                          *
  1507.  *      Process About menu command.                                         *
  1508.  *                                                                          *
  1509.  ****************************************************************************/
  1510.  
  1511. STATIC MRESULT APIENTRY About ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  1512.  
  1513.   /**************************************************************************
  1514.    * Find the instance data.                                                *
  1515.    **************************************************************************/
  1516.  
  1517.    PDATA Data = PDATA ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  1518.  
  1519.   /**************************************************************************
  1520.    * Invoke the About dialog.                                               *
  1521.    **************************************************************************/
  1522.  
  1523.    WinDlgBox ( HWND_DESKTOP, hwnd, PFNWP(AboutProcessor),
  1524.       Data->Library->QueryHandle(), IDD_ABOUT, 0 ) ;
  1525.  
  1526.   /**************************************************************************
  1527.    * Done.                                                                  *
  1528.    **************************************************************************/
  1529.  
  1530.    return ( MRFROMSHORT ( 0 ) ) ;
  1531. }
  1532.  
  1533. /****************************************************************************
  1534.  *                                                                          *
  1535.  *      Process Begin Drag message.                                         *
  1536.  *                                                                          *
  1537.  ****************************************************************************/
  1538.  
  1539. STATIC MRESULT APIENTRY BeginDrag ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  1540.  
  1541.   /**************************************************************************
  1542.    * Determine the new window position.                                     *
  1543.    **************************************************************************/
  1544.  
  1545.    TRACKINFO TrackInfo ;
  1546.    memset ( &TrackInfo, 0, sizeof(TrackInfo) ) ;
  1547.  
  1548.    TrackInfo.cxBorder = 1 ;
  1549.    TrackInfo.cyBorder = 1 ;
  1550.    TrackInfo.cxGrid = 1 ;
  1551.    TrackInfo.cyGrid = 1 ;
  1552.    TrackInfo.cxKeyboard = 8 ;
  1553.    TrackInfo.cyKeyboard = 8 ;
  1554.  
  1555.    HWND Frame = WinQueryWindow ( hwnd, QW_PARENT ) ;
  1556.  
  1557.    SWP Position ;
  1558.    WinQueryWindowPos ( Frame, &Position ) ;
  1559.    TrackInfo.rclTrack.xLeft   = Position.x ;
  1560.    TrackInfo.rclTrack.xRight  = Position.x + Position.cx ;
  1561.    TrackInfo.rclTrack.yBottom = Position.y ;
  1562.    TrackInfo.rclTrack.yTop    = Position.y + Position.cy ;
  1563.  
  1564.    WinQueryWindowPos ( HWND_DESKTOP, &Position ) ;
  1565.    TrackInfo.rclBoundary.xLeft   = Position.x ;
  1566.    TrackInfo.rclBoundary.xRight  = Position.x + Position.cx ;
  1567.    TrackInfo.rclBoundary.yBottom = Position.y ;
  1568.    TrackInfo.rclBoundary.yTop    = Position.y + Position.cy ;
  1569.  
  1570.    TrackInfo.ptlMinTrackSize.x = 0 ;
  1571.    TrackInfo.ptlMinTrackSize.y = 0 ;
  1572.    TrackInfo.ptlMaxTrackSize.x = Position.cx ;
  1573.    TrackInfo.ptlMaxTrackSize.y = Position.cy ;
  1574.  
  1575.    TrackInfo.fs = TF_MOVE | TF_STANDARD | TF_ALLINBOUNDARY ;
  1576.  
  1577.    if ( WinTrackRect ( HWND_DESKTOP, 0, &TrackInfo ) ) 
  1578.       WinSetWindowPos ( Frame, 0, TrackInfo.rclTrack.xLeft, TrackInfo.rclTrack.yBottom, 0, 0, SWP_MOVE ) ;
  1579.  
  1580.   /**************************************************************************
  1581.    * Done.                                                                  *
  1582.    **************************************************************************/
  1583.  
  1584.    return ( MRFROMSHORT ( 0 ) ) ;
  1585. }
  1586.  
  1587. /****************************************************************************
  1588.  *                                                                          *
  1589.  *      Process Mouse Button having been double-clicked.                    *
  1590.  *                                                                          *
  1591.  ****************************************************************************/
  1592.  
  1593. STATIC MRESULT APIENTRY ButtonDblClick ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  1594.  
  1595.   /**************************************************************************
  1596.    * Send message to self to stop hiding the controls.                      *
  1597.    **************************************************************************/
  1598.  
  1599.    WinPostMsg ( hwnd, WM_COMMAND,
  1600.       MPFROM2SHORT ( IDM_HIDE_CONTROLS, 0 ),
  1601.       MPFROM2SHORT ( CMDSRC_OTHER, TRUE ) ) ;
  1602.  
  1603.   /**************************************************************************
  1604.    * We're done here.                                                       *
  1605.    **************************************************************************/
  1606.  
  1607.    return ( 0 ) ;
  1608. }
  1609.  
  1610. /****************************************************************************
  1611.  *                                                                          *
  1612.  *      Process Presentation Parameter Changed notification.                *
  1613.  *                                                                          *
  1614.  ****************************************************************************/
  1615.  
  1616. STATIC MRESULT APIENTRY ContextMenu ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  1617.  
  1618.   /**************************************************************************
  1619.    * Find the instance data.                                                *
  1620.    **************************************************************************/
  1621.  
  1622.    PDATA Data = PDATA ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  1623.  
  1624.   /**************************************************************************
  1625.    * Invoke the window's context menu.                                      *
  1626.    **************************************************************************/
  1627.  
  1628.    WinSetPresParam ( Data->Menu, PP_FONTNAMESIZE, 0, PSZ("") ) ;
  1629.  
  1630.    WinPopupMenu ( hwnd, hwnd, Data->Menu, SHORT1FROMMP(mp1), SHORT2FROMMP(mp1),
  1631.       0, PU_HCONSTRAIN | PU_VCONSTRAIN | PU_KEYBOARD | PU_MOUSEBUTTON1 ) ;
  1632.  
  1633.   /**************************************************************************
  1634.    * Done.                                                                  *
  1635.    **************************************************************************/
  1636.  
  1637.    return ( MRESULT ( 0 ) ) ;
  1638. }
  1639.  
  1640. /****************************************************************************
  1641.  *                                                                          *
  1642.  *      Process Presentation Parameter Changed notification.                *
  1643.  *                                                                          *
  1644.  ****************************************************************************/
  1645.  
  1646. STATIC MRESULT APIENTRY PresParamChanged ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  1647.  
  1648.  /***************************************************************************
  1649.   * Find the instance data.                                                 *
  1650.   ***************************************************************************/
  1651.  
  1652.   PDATA Data = PDATA ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  1653.  
  1654.  /***************************************************************************
  1655.   * Get the presentation parameter that changed.                            *
  1656.   ***************************************************************************/
  1657.  
  1658.   switch ( LONGFROMMP(mp1) )
  1659.   {
  1660.  
  1661.    /*************************************************************************
  1662.     * If font, note the fact that we now have a font to be saved as         *
  1663.     *   part of the configuration.  Get the font metrics and resize         *
  1664.     *   the window appropriately.                                           *
  1665.     *************************************************************************/
  1666.  
  1667.     case PP_FONTNAMESIZE:
  1668.     {
  1669.       ULONG ppid ;
  1670.       if ( WinQueryPresParam ( hwnd, PP_FONTNAMESIZE, 0, &ppid,
  1671.         sizeof(Data->IniData.FontNameSize), &Data->IniData.FontNameSize,
  1672.         0 ) )
  1673.       {
  1674.         Data->IniData.fFontNameSize = TRUE ;
  1675.       }
  1676.       else
  1677.       {
  1678.         strcpy ( PCHAR(Data->IniData.FontNameSize), "" ) ;
  1679.         Data->IniData.fFontNameSize = FALSE ;
  1680.         PrfWriteProfileData ( Data->IniFile->QueryHandle(), PSZ(PROGRAM_NAME), PSZ("FontNameSize"), NULL, 0 ) ;
  1681.       }
  1682.  
  1683.       HPS hPS = WinGetPS ( hwnd ) ;
  1684.       RECTL Rectangle ;
  1685.       WinQueryWindowRect ( HWND_DESKTOP, &Rectangle ) ;
  1686.       WinDrawText ( hPS, 1, PSZ(" "), &Rectangle, 0, 0, DT_LEFT | DT_BOTTOM | DT_QUERYEXTENT ) ;
  1687.       Data->Width  = Rectangle.xRight - Rectangle.xLeft ;
  1688.       Data->Height = Rectangle.yTop - Rectangle.yBottom ;
  1689.       WinReleasePS ( hPS ) ;
  1690.       ResizeWindow ( hwnd ) ;
  1691.       break ;
  1692.     }
  1693.  
  1694.    /*************************************************************************
  1695.     * If background color, note the fact and repaint the window.            *
  1696.     *************************************************************************/
  1697.  
  1698.     case PP_BACKGROUNDCOLOR:
  1699.     {
  1700.       ULONG ppid ;
  1701.       if ( WinQueryPresParam ( hwnd, PP_BACKGROUNDCOLOR, 0, &ppid,
  1702.         sizeof(Data->IniData.BackColor), &Data->IniData.BackColor, 0 ) )
  1703.       {
  1704.         Data->IniData.fBackColor = TRUE ;
  1705.       }
  1706.       else
  1707.       {
  1708.         Data->IniData.BackColor = WinQuerySysColor ( HWND_DESKTOP, SYSCLR_WINDOW, 0 ) ;
  1709.         Data->IniData.fBackColor = FALSE ;
  1710.         PrfWriteProfileData ( Data->IniFile->QueryHandle(), PSZ(PROGRAM_NAME), PSZ("BackgroundColor"), NULL, 0 ) ;
  1711.       }
  1712.       WinInvalidateRect ( hwnd, 0, TRUE ) ;
  1713.       break ;
  1714.     }
  1715.  
  1716.    /*************************************************************************
  1717.     * If foreground color, note the fact and repaint the window.            *
  1718.     *************************************************************************/
  1719.  
  1720.     case PP_FOREGROUNDCOLOR:
  1721.     {
  1722.       ULONG ppid ;
  1723.       if ( WinQueryPresParam ( hwnd, PP_FOREGROUNDCOLOR, 0, &ppid,
  1724.         sizeof(Data->IniData.TextColor), &Data->IniData.TextColor, 0 ) )
  1725.       {
  1726.         Data->IniData.fTextColor = TRUE ;
  1727.       }
  1728.       else
  1729.       {
  1730.         Data->IniData.TextColor = WinQuerySysColor ( HWND_DESKTOP, SYSCLR_OUTPUTTEXT, 0 ) ;
  1731.         Data->IniData.fTextColor = FALSE ;
  1732.         PrfWriteProfileData ( Data->IniFile->QueryHandle(), PSZ(PROGRAM_NAME), PSZ("ForegroundColor"), NULL, 0 ) ;
  1733.       }
  1734.       WinInvalidateRect ( hwnd, 0, TRUE ) ;
  1735.       break ;
  1736.     }
  1737.   }
  1738.  
  1739.  /***************************************************************************
  1740.   * Return through the default processor, letting window activation         *
  1741.   *   and other system functions occur.                                     *
  1742.   ***************************************************************************/
  1743.  
  1744.   return ( WinDefWindowProc ( hwnd, msg, mp1, mp2 ) ) ;
  1745. }
  1746.  
  1747. /****************************************************************************
  1748.  *                                                                          *
  1749.  *      Process System Color Change notification.                           *
  1750.  *                                                                          *
  1751.  ****************************************************************************/
  1752.  
  1753. STATIC MRESULT APIENTRY SysColorChange ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  1754.  
  1755.  /***************************************************************************
  1756.   * Find the instance data.                                                 *
  1757.   ***************************************************************************/
  1758.  
  1759.   PDATA Data = PDATA ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  1760.  
  1761.  /***************************************************************************
  1762.   * If we aren't using custom colors, then query for the new defaults.      *
  1763.   ***************************************************************************/
  1764.  
  1765.   if ( NOT Data->IniData.fBackColor )
  1766.   {
  1767.     Data->IniData.BackColor = WinQuerySysColor ( HWND_DESKTOP, SYSCLR_WINDOW, 0 ) ;
  1768.   }
  1769.  
  1770.   if ( NOT Data->IniData.fTextColor )
  1771.   {
  1772.     Data->IniData.TextColor = WinQuerySysColor ( HWND_DESKTOP, SYSCLR_OUTPUTTEXT, 0 ) ;
  1773.   }
  1774.  
  1775.  /***************************************************************************
  1776.   * Return value must be NULL, according to the documentation.              *
  1777.   ***************************************************************************/
  1778.  
  1779.   return ( MRFROMP ( NULL ) ) ;
  1780. }
  1781.  
  1782. /****************************************************************************
  1783.  *                                                                          *
  1784.  *      Process Query for Keys Help resource id.                            *
  1785.  *                                                                          *
  1786.  ****************************************************************************/
  1787.  
  1788. STATIC MRESULT APIENTRY QueryKeysHelp ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  1789.  
  1790.  /***************************************************************************
  1791.   * Simply return the ID of the Keys Help panel.                            *
  1792.   ***************************************************************************/
  1793.  
  1794.   return ( (MRESULT) IDM_KEYS_HELP ) ;
  1795. }
  1796.  
  1797. /****************************************************************************
  1798.  *                                                                          *
  1799.  *      Process Help Manager Error                                          *
  1800.  *                                                                          *
  1801.  ****************************************************************************/
  1802.  
  1803. STATIC MRESULT APIENTRY HelpError ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  1804.  
  1805.  /***************************************************************************
  1806.   * Local Declarations                                                      *
  1807.   ***************************************************************************/
  1808.  
  1809.   static struct
  1810.   {
  1811.     ULONG Error ;
  1812.     USHORT StringId ;
  1813.   }
  1814.   HelpErrors [] =
  1815.   {
  1816.     { HMERR_NO_FRAME_WND_IN_CHAIN,     IDS_HMERR_NO_FRAME_WND_IN_CHAIN },
  1817.     { HMERR_INVALID_ASSOC_APP_WND,     IDS_HMERR_INVALID_ASSOC_APP_WND },
  1818.     { HMERR_INVALID_ASSOC_HELP_INST,   IDS_HMERR_INVALID_ASSOC_HELP_IN },
  1819.     { HMERR_INVALID_DESTROY_HELP_INST, IDS_HMERR_INVALID_DESTROY_HELP_ },
  1820.     { HMERR_NO_HELP_INST_IN_CHAIN,     IDS_HMERR_NO_HELP_INST_IN_CHAIN },
  1821.     { HMERR_INVALID_HELP_INSTANCE_HDL, IDS_HMERR_INVALID_HELP_INSTANCE },
  1822.     { HMERR_INVALID_QUERY_APP_WND,     IDS_HMERR_INVALID_QUERY_APP_WND },
  1823.     { HMERR_HELP_INST_CALLED_INVALID,  IDS_HMERR_HELP_INST_CALLED_INVA },
  1824.     { HMERR_HELPTABLE_UNDEFINE,        IDS_HMERR_HELPTABLE_UNDEFINE    },
  1825.     { HMERR_HELP_INSTANCE_UNDEFINE,    IDS_HMERR_HELP_INSTANCE_UNDEFIN },
  1826.     { HMERR_HELPITEM_NOT_FOUND,        IDS_HMERR_HELPITEM_NOT_FOUND    },
  1827.     { HMERR_INVALID_HELPSUBITEM_SIZE,  IDS_HMERR_INVALID_HELPSUBITEM_S },
  1828.     { HMERR_HELPSUBITEM_NOT_FOUND,     IDS_HMERR_HELPSUBITEM_NOT_FOUND },
  1829.     { HMERR_INDEX_NOT_FOUND,           IDS_HMERR_INDEX_NOT_FOUND       },
  1830.     { HMERR_CONTENT_NOT_FOUND,         IDS_HMERR_CONTENT_NOT_FOUND     },
  1831.     { HMERR_OPEN_LIB_FILE,             IDS_HMERR_OPEN_LIB_FILE         },
  1832.     { HMERR_READ_LIB_FILE,             IDS_HMERR_READ_LIB_FILE         },
  1833.     { HMERR_CLOSE_LIB_FILE,            IDS_HMERR_CLOSE_LIB_FILE        },
  1834.     { HMERR_INVALID_LIB_FILE,          IDS_HMERR_INVALID_LIB_FILE      },
  1835.     { HMERR_NO_MEMORY,                 IDS_HMERR_NO_MEMORY             },
  1836.     { HMERR_ALLOCATE_SEGMENT,          IDS_HMERR_ALLOCATE_SEGMENT      },
  1837.     { HMERR_FREE_MEMORY,               IDS_HMERR_FREE_MEMORY           },
  1838.     { HMERR_PANEL_NOT_FOUND,           IDS_HMERR_PANEL_NOT_FOUND       },
  1839.     { HMERR_DATABASE_NOT_OPEN,         IDS_HMERR_DATABASE_NOT_OPEN     },
  1840.     { 0,                               IDS_HMERR_UNKNOWN               }
  1841.   } ;
  1842.  
  1843.   ULONG ErrorCode = (ULONG) LONGFROMMP ( mp1 ) ;
  1844.  
  1845.  /***************************************************************************
  1846.   * Find the instance data.                                                 *
  1847.   ***************************************************************************/
  1848.  
  1849.   PDATA Data = PDATA ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  1850.  
  1851.  /***************************************************************************
  1852.   * Find the error code in the message table.                               *
  1853.   ***************************************************************************/
  1854.  
  1855.   int Index = 0 ;
  1856.   while ( HelpErrors[Index].Error
  1857.     AND ( HelpErrors[Index].Error != ErrorCode ) )
  1858.   {
  1859.     Index ++ ;
  1860.   }
  1861.  
  1862.  /***************************************************************************
  1863.   * Get the message texts.                                                  *
  1864.   ***************************************************************************/
  1865.  
  1866.   ResourceString Title ( Data->Library->QueryHandle(), IDS_HMERR ) ;
  1867.  
  1868.   ResourceString Message ( Data->Library->QueryHandle(), HelpErrors[Index].StringId ) ;
  1869.  
  1870.  /***************************************************************************
  1871.   * Display the error message.                                              *
  1872.   ***************************************************************************/
  1873.  
  1874.   WinMessageBox
  1875.   (
  1876.     HWND_DESKTOP,
  1877.     hwnd,
  1878.     PSZ(Message),
  1879.     PSZ(Title),
  1880.     0,
  1881.     MB_OK | MB_WARNING
  1882.   ) ;
  1883.  
  1884.  /***************************************************************************
  1885.   * Return zero, indicating that the message was processed.                 *
  1886.   ***************************************************************************/
  1887.  
  1888.   return ( MRFROMSHORT ( 0 ) ) ;
  1889. }
  1890.  
  1891. /****************************************************************************
  1892.  *                                                                          *
  1893.  *      Process "Extended Help Undefined" notification                      *
  1894.  *                                                                          *
  1895.  ****************************************************************************/
  1896.  
  1897. STATIC MRESULT APIENTRY ExtHelpUndefined ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  1898.  
  1899.  /***************************************************************************
  1900.   * Find the instance data.                                                 *
  1901.   ***************************************************************************/
  1902.  
  1903.   PDATA Data = PDATA ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  1904.  
  1905.  /***************************************************************************
  1906.   * Get the message texts.                                                  *
  1907.   ***************************************************************************/
  1908.  
  1909.   ResourceString Title ( Data->Library->QueryHandle(), IDS_HMERR ) ;
  1910.  
  1911.   ResourceString Message ( Data->Library->QueryHandle(), IDS_HMERR_EXTHELPUNDEFINED ) ;
  1912.  
  1913.  /***************************************************************************
  1914.   * Display the error message.                                              *
  1915.   ***************************************************************************/
  1916.  
  1917.   WinMessageBox
  1918.   (
  1919.     HWND_DESKTOP,
  1920.     hwnd,
  1921.     PSZ(Message),
  1922.     PSZ(Title),
  1923.     0,
  1924.     MB_OK | MB_WARNING
  1925.   ) ;
  1926.  
  1927.  /***************************************************************************
  1928.   * Return zero, indicating that the message was processed.                 *
  1929.   ***************************************************************************/
  1930.  
  1931.   return ( MRFROMSHORT ( 0 ) ) ;
  1932. }
  1933.  
  1934. /****************************************************************************
  1935.  *                                                                          *
  1936.  *      Process "Help Subitem Not Found" notification                       *
  1937.  *                                                                          *
  1938.  ****************************************************************************/
  1939.  
  1940. STATIC MRESULT APIENTRY HelpSubitemNotFound ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  1941.  
  1942.  /***************************************************************************
  1943.   * Find the instance data.                                                 *
  1944.   ***************************************************************************/
  1945.  
  1946.   PDATA Data = PDATA ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  1947.  
  1948.  /***************************************************************************
  1949.   * Get the title text.                                                     *
  1950.   ***************************************************************************/
  1951.  
  1952.   ResourceString Title ( Data->Library->QueryHandle(), IDS_HMERR ) ;
  1953.  
  1954.  /***************************************************************************
  1955.   * Format the error message.                                               *
  1956.   ***************************************************************************/
  1957.  
  1958.   USHORT Topic = (USHORT) SHORT1FROMMP ( mp2 ) ;
  1959.   USHORT Subtopic = (USHORT) SHORT2FROMMP ( mp2 ) ;
  1960.  
  1961.   ResourceString Frame   ( Data->Library->QueryHandle(), IDS_HELPMODE_FRAME ) ;
  1962.   ResourceString Menu    ( Data->Library->QueryHandle(), IDS_HELPMODE_MENU ) ;
  1963.   ResourceString Window  ( Data->Library->QueryHandle(), IDS_HELPMODE_WINDOW ) ;
  1964.   ResourceString Unknown ( Data->Library->QueryHandle(), IDS_HELPMODE_UNKNOWN ) ;
  1965.  
  1966.   PBYTE Mode ;
  1967.   switch ( SHORT1FROMMP ( mp1 ) )
  1968.   {
  1969.     case HLPM_FRAME:
  1970.       Mode = PSZ(Frame) ;
  1971.       break ;
  1972.  
  1973.     case HLPM_MENU:
  1974.       Mode = PSZ(Menu) ;
  1975.       break ;
  1976.  
  1977.     case HLPM_WINDOW:
  1978.       Mode = PSZ(Window) ;
  1979.       break ;
  1980.  
  1981.     default:
  1982.       Mode = PSZ(Unknown) ;
  1983.   }
  1984.  
  1985.   ResourceString Format ( Data->Library->QueryHandle(), IDS_HELPSUBITEMNOTFOUND ) ;
  1986.  
  1987.   BYTE Message [200] ;
  1988.   sprintf ( PCHAR(Message), PCHAR(Format), Mode, Topic, Subtopic ) ;
  1989.  
  1990.  /***************************************************************************
  1991.   * Display the error message.                                              *
  1992.   ***************************************************************************/
  1993.  
  1994.   WinMessageBox
  1995.   (
  1996.     HWND_DESKTOP,
  1997.     hwnd,
  1998.     Message,
  1999.     PSZ(Title),
  2000.     0,
  2001.     MB_OK | MB_WARNING
  2002.   ) ;
  2003.  
  2004.  /***************************************************************************
  2005.   * Return zero, indicating that the message was processed.                 *
  2006.   ***************************************************************************/
  2007.  
  2008.   return ( MRFROMSHORT ( 0 ) ) ;
  2009. }
  2010.  
  2011. /****************************************************************************
  2012.  *                                                                          *
  2013.  *      Process Refresh message.                                            *
  2014.  *                                                                          *
  2015.  ****************************************************************************/
  2016.  
  2017. STATIC MRESULT APIENTRY Refresh ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  2018.  
  2019.  /***************************************************************************
  2020.   * Find the instance data.                                                 *
  2021.   ***************************************************************************/
  2022.  
  2023.   PDATA Data = PDATA ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  2024.  
  2025.  /***************************************************************************
  2026.   * If we're supposed to float the window, do so here.                      *
  2027.   ***************************************************************************/
  2028.  
  2029.   if ( Data->IniData.Float )
  2030.     WinSetWindowPos ( WinQueryWindow(hwnd,QW_PARENT), HWND_TOP, 0, 0, 0, 0, SWP_ZORDER ) ;
  2031.  
  2032.  /***************************************************************************
  2033.   * Save the idle counter.                                                  *
  2034.   ***************************************************************************/
  2035.  
  2036.   Data->IniData.IdleCount = LONGFROMMP ( mp1 ) ;
  2037.  
  2038.  /***************************************************************************
  2039.   * Determine if drive mask has changed.                                    *
  2040.   ***************************************************************************/
  2041.  
  2042.   ULONG Drive ;
  2043.   ULONG Drives ;
  2044.   DosQueryCurrentDisk ( &Drive, &Drives ) ;
  2045.  
  2046.   if ( Drives != Data->Drives ) {
  2047.  
  2048.    /*************************************************************************
  2049.     * It has.  First save the display options.                              *
  2050.     *************************************************************************/
  2051.  
  2052.     SaveApplication ( hwnd, WM_SAVEAPPLICATION, 0, 0 ) ;
  2053.  
  2054.    /*************************************************************************
  2055.     * Next, update the drive item list.                                     *
  2056.     *************************************************************************/
  2057.  
  2058.     UpdateDriveList ( Data->Proc->QueryAnchor(), Data->Library->QueryHandle(), Data->IniFile->QueryHandle(),
  2059.       &Data->IniData, Data->pDdeServer, Data->Drives, Drives ) ;
  2060.  
  2061.    /*************************************************************************
  2062.     * Save the updated drive mask.                                          *
  2063.     *************************************************************************/
  2064.  
  2065.     Data->Drives = Drives ;
  2066.  
  2067.    /*************************************************************************
  2068.     * Resize the window to accommodate the new option list.                 *
  2069.     *************************************************************************/
  2070.  
  2071.     ResizeWindow ( hwnd ) ;
  2072.   }
  2073.  
  2074.  /***************************************************************************
  2075.   * Update the statistics.                                                  *
  2076.   ***************************************************************************/
  2077.  
  2078.   UpdateWindow ( hwnd, Data, FALSE ) ;
  2079.  
  2080.  /***************************************************************************
  2081.   * Return zero, indicating that the message was processed.                 *
  2082.   ***************************************************************************/
  2083.  
  2084.   return ( MRFROMSHORT ( 0 ) ) ;
  2085. }
  2086.  
  2087.  
  2088. /****************************************************************************
  2089.  *                                                                          *
  2090.  *      Process DDE Initiate request                                        *
  2091.  *                                                                          *
  2092.  ****************************************************************************/
  2093.  
  2094. STATIC MRESULT APIENTRY Dde_Initiate ( HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2 ) {
  2095.  
  2096.  /***************************************************************************
  2097.   * Find the instance data.                                                 *
  2098.   ***************************************************************************/
  2099.  
  2100.   PDATA Data = PDATA ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  2101.  
  2102.  /***************************************************************************
  2103.   * Pass the request to the DDE Server.                                     *
  2104.   ***************************************************************************/
  2105.  
  2106.   Data->pDdeServer->Initiate ( hwnd, HWNDFROMMP(mp1), PDDEINIT(PVOIDFROMMP(mp2)) ) ;
  2107.  
  2108.  /***************************************************************************
  2109.   * Return zero, indicating that the message was processed.                 *
  2110.   ***************************************************************************/
  2111.  
  2112.   return ( MRFROMSHORT ( 0 ) ) ;
  2113. }
  2114.  
  2115.  
  2116. /****************************************************************************
  2117.  *                                                                          *
  2118.  *                      Get Expanded INI Information                        *
  2119.  *                                                                          *
  2120.  ****************************************************************************/
  2121.  
  2122. STATIC int GetIniData ( HAB Anchor, HMODULE Library, HINI IniHandle, PINIDATA IniData, Dde_Server *pDdeServer ) {
  2123.  
  2124.  /***************************************************************************
  2125.   * Get the basic INI information.                                          *
  2126.   ***************************************************************************/
  2127.  
  2128.   if ( GetIniData ( IniHandle, IniData ) )
  2129.      return ( 1 ) ;
  2130.  
  2131.  /***************************************************************************
  2132.   * Initialize the global resource strings.                                 *
  2133.   ***************************************************************************/
  2134.  
  2135.   IniData->Day        = new ResourceString ( Library, IDS_DAY ) ;
  2136.   IniData->Days       = new ResourceString ( Library, IDS_DAYS ) ;
  2137.   IniData->DaysOfWeek = new ResourceString ( Library, IDS_DAYSOFWEEK ) ;
  2138.   IniData->DriveError = new ResourceString ( Library, IDS_DRIVEERROR ) ;
  2139.  
  2140.  /***************************************************************************
  2141.   * Get country information.                                                *
  2142.   ***************************************************************************/
  2143.  
  2144.   COUNTRYCODE CountryCode ;
  2145.   ULONG Count ;
  2146.   ULONG Status ;
  2147.  
  2148.   CountryCode.country = 0 ;
  2149.   CountryCode.codepage = 0 ;
  2150.  
  2151.   Status = DosGetCtryInfo ( sizeof(IniData->CountryInfo), &CountryCode,
  2152.     &IniData->CountryInfo, &Count ) ;
  2153.   if ( Status ) {
  2154.     IniData->CountryInfo.fsDateFmt = DATEFMT_MM_DD_YY ;
  2155.     IniData->CountryInfo.fsTimeFmt = 0 ;
  2156.     IniData->CountryInfo.szDateSeparator[0] = '/' ;
  2157.     IniData->CountryInfo.szDateSeparator[1] = 0 ;
  2158.     IniData->CountryInfo.szTimeSeparator[0] = ':' ;
  2159.     IniData->CountryInfo.szTimeSeparator[1] = 0 ;
  2160.     IniData->CountryInfo.szThousandsSeparator[0] = ',' ;
  2161.     IniData->CountryInfo.szThousandsSeparator[1] = 0 ;
  2162.   }
  2163.  
  2164.   char Text [10] ;
  2165.   ULONG Size = 10 ;
  2166.   if ( PrfQueryProfileData ( HINI_USERPROFILE, PSZ("PM_National"), PSZ("iDate"), Text, &Size ) )
  2167.      IniData->CountryInfo.fsDateFmt = atoi ( Text ) ;
  2168.  
  2169.   Size = 10 ;
  2170.   if ( PrfQueryProfileData ( HINI_USERPROFILE, PSZ("PM_National"), PSZ("iTime"), Text, &Size ) )
  2171.      IniData->CountryInfo.fsTimeFmt = UCHAR ( atoi ( Text ) ) ;
  2172.  
  2173.   Size = 10 ;
  2174.   if ( PrfQueryProfileData ( HINI_USERPROFILE, PSZ("PM_National"), PSZ("iCountry"), Text, &Size ) )
  2175.      IniData->idCountry = atoi ( Text ) ;
  2176.  
  2177.   Size = 2 ;
  2178.   PrfQueryProfileData ( HINI_USERPROFILE, PSZ("PM_National"), PSZ("sDate"), IniData->CountryInfo.szDateSeparator, &Size ) ;
  2179.  
  2180.   Size = 2 ;
  2181.   PrfQueryProfileData ( HINI_USERPROFILE, PSZ("PM_National"), PSZ("sTime"), IniData->CountryInfo.szTimeSeparator, &Size ) ;
  2182.  
  2183.   Size = 3 ;
  2184.   strcpy ( IniData->szAm, "am" ) ;
  2185.   PrfQueryProfileData ( HINI_USERPROFILE, PSZ("PM_National"), PSZ("s1159"), IniData->szAm, &Size ) ;
  2186.  
  2187.   Size = 3 ;
  2188.   strcpy ( IniData->szPm, "pm" ) ;
  2189.   PrfQueryProfileData ( HINI_USERPROFILE, PSZ("PM_National"), PSZ("s2359"), IniData->szPm, &Size ) ;
  2190.  
  2191.   Size = 2 ;
  2192.   PrfQueryProfileData ( HINI_USERPROFILE, PSZ("PM_National"), PSZ("sThousand"), IniData->CountryInfo.szThousandsSeparator, &Size ) ;
  2193.  
  2194.  /***************************************************************************
  2195.   * Get the SWAPPATH statement from CONFIG.SYS.                             *
  2196.   ***************************************************************************/
  2197.  
  2198.   PSZ Swappath = ScanSystemConfig ( Anchor, PSZ("SWAPPATH") ) ;
  2199.  
  2200.   if ( Swappath == NULL )
  2201.     Swappath = PSZ("C:\\OS2\\SYSTEM 0") ;
  2202.  
  2203.   char *p = CopyString ( PCHAR(IniData->SwapPath), PCHAR(Swappath) ) ;
  2204.   sscanf ( p, " %li", &IniData->MinFree ) ;
  2205.  
  2206.  /***************************************************************************
  2207.   * Find out where the spool work directory is.                             *
  2208.   ***************************************************************************/
  2209.  
  2210.   IniData->SpoolPath = 0 ;
  2211.  
  2212.   if ( PrfQueryProfileSize ( HINI_PROFILE, PSZ("PM_SPOOLER"), PSZ("DIR"), &Size ) ) {
  2213.     IniData->SpoolPath = PSZ ( malloc ( (int)Size ) ) ;
  2214.     if ( IniData->SpoolPath ) {
  2215.       if ( PrfQueryProfileData ( HINI_PROFILE, PSZ("PM_SPOOLER"), PSZ("DIR"), IniData->SpoolPath, &Size ) ) {
  2216.         PBYTE p = PBYTE( strchr ( PCHAR(IniData->SpoolPath), ';' ) ) ;
  2217.         if ( p ) {
  2218.           *p = 0 ;
  2219.         }
  2220.       } else {
  2221.         free ( IniData->SpoolPath ) ;
  2222.         IniData->SpoolPath = 0 ;
  2223.       }
  2224.     }
  2225.   }
  2226.  
  2227.   if ( IniData->SpoolPath == 0 )
  2228.      IniData->SpoolPath = PSZ ( "C:\\SPOOL" ) ;
  2229.  
  2230.  /***************************************************************************
  2231.   * Build the fixed portion of the item list.                               *
  2232.   ***************************************************************************/
  2233.  
  2234.   ResourceString ClockLabel ( Library, IDS_CLOCK ) ;
  2235.   IniData->Items[ITEM_CLOCK].pItem = new Clock ( ITEM_CLOCK,
  2236.     "ShowClock", ClockLabel, ClockLabel, pDdeServer, "Items",
  2237.     IniData->CountryInfo, IniData->szAm, IniData->szPm,
  2238.     IniData->DaysOfWeek, IniData->ShowSeconds ) ;
  2239.  
  2240.   ResourceString ElapsedLabel ( Library, IDS_ELAPSED ) ;
  2241.   IniData->Items[ITEM_ELAPSEDTIME].pItem = new ElapsedTime ( ITEM_ELAPSEDTIME,
  2242.     "ShowElapsed", ElapsedLabel, ElapsedLabel, pDdeServer, "Items",
  2243.     IniData->CountryInfo, IniData->Day,
  2244.     IniData->Days, IniData->ShowSeconds ) ;
  2245.  
  2246.   ResourceString MemoryLabel ( Library, IDS_MEMORY ) ;
  2247.   IniData->Items[ITEM_MEMORYFREE].pItem = new MemoryFree ( ITEM_MEMORYFREE,
  2248.     "ShowMemory", MemoryLabel, MemoryLabel, pDdeServer, "Items",
  2249.     IniData->CountryInfo, IniData->ShowK ) ;
  2250.  
  2251.   ResourceString VirtualLabel ( Library, IDS_VIRTUAL ) ;
  2252.   IniData->Items[ITEM_VIRTUALFREE].pItem = new VirtualFree ( ITEM_VIRTUALFREE,
  2253.     "ShowVirtual", VirtualLabel, VirtualLabel, pDdeServer, "Items",
  2254.     IniData->CountryInfo, IniData->ShowK ) ;
  2255.  
  2256.   ResourceString SwapSizeLabel ( Library, IDS_SWAPSIZE ) ;
  2257.   IniData->Items[ITEM_SWAPFILESIZE].pItem = new SwapSize ( ITEM_SWAPFILESIZE,
  2258.     "ShowSwapsize", SwapSizeLabel, SwapSizeLabel, pDdeServer, "Items",
  2259.     IniData->CountryInfo, IniData->ShowK, IniData->SwapPath ) ;
  2260.  
  2261.   ResourceString SwapFreeLabel ( Library, IDS_SWAPFREE ) ;
  2262.   IniData->Items[ITEM_SWAPDISKFREE].pItem = new SwapFree ( ITEM_SWAPDISKFREE,
  2263.     "ShowSwapfree", SwapFreeLabel, SwapFreeLabel, pDdeServer, "Items",
  2264.     IniData->CountryInfo, IniData->ShowK, IniData->SwapPath, IniData->MinFree ) ;
  2265.  
  2266.   ResourceString SwapSlackLabel ( Library, IDS_SWAPSLACK ) ;
  2267.   IniData->Items[ITEM_SWAPFILESLACK].pItem = new SwapSlack ( ITEM_SWAPFILESLACK,
  2268.     "ShowSwapSlack", SwapSlackLabel, SwapSlackLabel, pDdeServer, "Items",
  2269.     IniData->CountryInfo, IniData->ShowK,
  2270.     (VirtualFree*)IniData->Items[ITEM_VIRTUALFREE].pItem,
  2271.     (SwapFree*)IniData->Items[ITEM_SWAPDISKFREE].pItem,
  2272.     (MemoryFree*)IniData->Items[ITEM_MEMORYFREE].pItem ) ;
  2273.  
  2274.   ResourceString SpoolSizeLabel ( Library, IDS_SPOOLSIZE ) ;
  2275.   IniData->Items[ITEM_SPOOLFILESIZE].pItem = new SpoolSize ( ITEM_SPOOLFILESIZE,
  2276.     "ShowSpoolSize", SpoolSizeLabel, SpoolSizeLabel, pDdeServer, "Items",
  2277.     IniData->CountryInfo, IniData->ShowK, IniData->SpoolPath ) ;
  2278.  
  2279.   ResourceString CpuLoadLabel ( Library, IDS_CPULOAD ) ;
  2280.   IniData->Items[ITEM_CPULOAD].pItem = new CpuLoad ( ITEM_CPULOAD,
  2281.     "ShowCpuLoad", CpuLoadLabel, CpuLoadLabel, pDdeServer, "Items",
  2282.     IniData->MaxCount, &IniData->IdleCount ) ;
  2283.  
  2284.   ResourceString TaskCountLabel ( Library, IDS_TASKCOUNT ) ;
  2285.   IniData->Items[ITEM_TASKCOUNT].pItem = new TaskCount ( ITEM_TASKCOUNT,
  2286.     "ShowTaskCount", TaskCountLabel, TaskCountLabel, pDdeServer, "Items",
  2287.     Anchor ) ;
  2288.  
  2289.   ResourceString ProcessCountLabel ( Library, IDS_PROCESSCOUNT ) ;
  2290.   IniData->Items[ITEM_PROCESSCOUNT].pItem = new ProcessCount ( ITEM_PROCESSCOUNT,
  2291.     "ShowProcessCount", ProcessCountLabel, ProcessCountLabel, pDdeServer, "Items" ) ;
  2292.  
  2293.   ResourceString ThreadCountLabel ( Library, IDS_THREADCOUNT ) ;
  2294.   IniData->Items[ITEM_THREADCOUNT].pItem = new ThreadCount ( ITEM_THREADCOUNT,
  2295.     "ShowThreadCount", ThreadCountLabel, ThreadCountLabel, pDdeServer, "Items" ) ;
  2296.  
  2297.   ResourceString TotalFreeLabel ( Library, IDS_TOTALFREE ) ;
  2298.   IniData->Items[ITEM_TOTALFREE].pItem = new TotalFree ( ITEM_TOTALFREE,
  2299.     "ShowTotalFree", TotalFreeLabel, TotalFreeLabel, pDdeServer, "Items",
  2300.     IniData->CountryInfo, IniData->ShowK, 0 ) ;
  2301.  
  2302.   for ( int i=0; i<ITEM_BASE_COUNT; i++ ) {
  2303.  
  2304.      Item *pItem = IniData->Items[i].pItem ;
  2305.  
  2306.      BOOL Flag = TRUE ;
  2307.      if ( PrfQueryProfileSize ( IniHandle, PSZ(PROGRAM_NAME), PSZ(pItem->QueryName()), &Size )
  2308.         AND ( ( Size == sizeof(Flag) ) OR ( Size == sizeof(short) ) )
  2309.         AND PrfQueryProfileData ( IniHandle, PSZ(PROGRAM_NAME), PSZ(pItem->QueryName()), &Flag, &Size ) ) {
  2310.  
  2311.      } /* endif */
  2312.  
  2313.      if ( Flag )
  2314.         IniData->Items[i].pItem->SetFlag() ;
  2315.      else
  2316.         IniData->Items[i].pItem->ResetFlag() ;
  2317.  
  2318.      char Tag [80] ;
  2319.      strcpy ( Tag, PCHAR(IniData->Items[i].pItem->QueryName()) ) ;
  2320.      strcat ( Tag, " Label" ) ;
  2321.      IniData->Items[i].fLabel = FALSE ;
  2322.      if ( PrfQueryProfileSize ( IniHandle, PSZ(PROGRAM_NAME), PSZ(Tag), &Size )
  2323.         AND ( Size == sizeof(IniData->Items[i].Label) )
  2324.         AND PrfQueryProfileData ( IniHandle, PSZ(PROGRAM_NAME), PSZ(Tag), &IniData->Items[i].Label, &Size )
  2325.         AND IniData->Items[i].Label[0] ) {
  2326.  
  2327.         IniData->Items[i].fLabel = TRUE ;
  2328.         IniData->Items[i].pItem->SetLabel ( IniData->Items[i].Label ) ;
  2329.  
  2330.      } /* endif */
  2331.  
  2332.   } /* endfor */
  2333.  
  2334.  /***************************************************************************
  2335.   * Add items for each drive on the system.                                 *
  2336.   ***************************************************************************/
  2337.  
  2338.   ULONG Drive, Drives ;
  2339.   DosQueryCurrentDisk ( &Drive, &Drives ) ;
  2340.   UpdateDriveList ( Anchor, Library, IniHandle, IniData, pDdeServer, 0, Drives ) ;
  2341.  
  2342.   return ( 0 ) ;
  2343. }
  2344.  
  2345. /****************************************************************************
  2346.  *                                                                          *
  2347.  *      Scan CONFIG.SYS for a keyword.  Return the value.                   *
  2348.  *                                                                          *
  2349.  ****************************************************************************/
  2350.  
  2351. STATIC PSZ ScanSystemConfig ( HAB Anchor, PSZ Keyword ) {
  2352.  
  2353.  /***************************************************************************
  2354.   * Get the boot drive number from the global information segment.          *
  2355.   ***************************************************************************/
  2356.  
  2357.   ULONG BootDrive ;
  2358.   DosQuerySysInfo ( QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &BootDrive, sizeof(BootDrive) ) ;
  2359.  
  2360.  /***************************************************************************
  2361.   * Convert the keyword to upper case.                                      *
  2362.   ***************************************************************************/
  2363.  
  2364.   WinUpper ( Anchor, 0, 0, Keyword ) ;
  2365.  
  2366.  /***************************************************************************
  2367.   * Build the CONFIG.SYS path.                                              *
  2368.   ***************************************************************************/
  2369.  
  2370.   char Path [_MAX_PATH] ;
  2371.   Path[0] = (char) ( BootDrive + 'A' - 1 ) ;
  2372.   Path[1] = 0 ;
  2373.   strcat ( Path, ":\\CONFIG.SYS" ) ;
  2374.  
  2375.  /***************************************************************************
  2376.   * Open CONFIG.SYS for reading.                                            *
  2377.   ***************************************************************************/
  2378.  
  2379.   FILE *File = fopen ( Path, "r" ) ;
  2380.   if ( NOT File )
  2381.     return ( 0 ) ;
  2382.  
  2383.  /***************************************************************************
  2384.   * While there're more lines in CONFIG.SYS, read a line and check it.      *
  2385.   ***************************************************************************/
  2386.  
  2387.   static char Buffer [500] ;
  2388.   while ( fgets ( Buffer, sizeof(Buffer), File ) ) {
  2389.  
  2390.    /*************************************************************************
  2391.     * Clean any trailing newline character from the input string.           *
  2392.     *************************************************************************/
  2393.  
  2394.     if ( Buffer[strlen(Buffer)-1] == '\n' )
  2395.       Buffer[strlen(Buffer)-1] = 0 ;
  2396.  
  2397.    /*************************************************************************
  2398.     * If keyword starts the line, we've found the line we want.  Close      *
  2399.     *   the file and return a pointer to the parameter text.                *
  2400.     *************************************************************************/
  2401.  
  2402.     WinUpper ( Anchor, 0, 0, PSZ(Buffer) ) ;
  2403.  
  2404.     char *p = Buffer ;
  2405.     while ( *p AND ( ( *p == ' ' ) OR ( *p == '\t' ) ) ) p++ ;
  2406.  
  2407.     if ( strncmp ( p, PCHAR(Keyword), strlen(PCHAR(Keyword)) ) )
  2408.        continue ;
  2409.  
  2410.     p += strlen(PCHAR(Keyword)) ;
  2411.     while ( *p AND ( ( *p == ' ' ) OR ( *p == '\t' ) ) ) p++ ;
  2412.  
  2413.     if ( *p++ != '=' )
  2414.        continue ;
  2415.  
  2416.     while ( *p AND ( ( *p == ' ' ) OR ( *p == '\t' ) ) ) p++ ;
  2417.  
  2418.     fclose ( File ) ;
  2419.     return ( PSZ(p) ) ;
  2420.  
  2421.   }
  2422.  
  2423.  /***************************************************************************
  2424.   * Close the file.  We haven't found the line we wanted.                   *
  2425.   ***************************************************************************/
  2426.  
  2427.   fclose ( File ) ;
  2428.  
  2429.   return ( 0 ) ;
  2430. }
  2431.  
  2432. /****************************************************************************
  2433.  *                                                                          *
  2434.  *                          Copy Quoted String                              *
  2435.  *                                                                          *
  2436.  ****************************************************************************/
  2437.  
  2438. STATIC char *CopyString ( char *Buffer, char *Original ) {
  2439.    char *p1 = PCHAR(Original), *p2 = Buffer ;
  2440.    BOOL Quoted = FALSE ;
  2441.    *p2 = 0 ;
  2442.    while ( *p1 ) {
  2443.       if ( Quoted ) {
  2444.          if ( *p1 == '"' ) {
  2445.             Quoted = FALSE ;
  2446.          } else {
  2447.             *p2++ = *p1 ;
  2448.             *p2 = 0 ;
  2449.          } /* endif */
  2450.       } else {
  2451.          if ( *p1 == '"' ) {
  2452.             Quoted = TRUE ;
  2453.          } else if ( ( *p1 == ' ' ) OR ( *p1 == '\t' ) ) {
  2454.             break ;
  2455.          } else {
  2456.             *p2++ = *p1 ;
  2457.             *p2 = 0 ;
  2458.          } /* endif */
  2459.       } /* endif */
  2460.       p1 ++ ;
  2461.    } /* endwhile */
  2462.    return ( p1 ) ;
  2463. }
  2464.  
  2465. /****************************************************************************
  2466.  *                                                                          *
  2467.  *                       Resize Client Window                               *
  2468.  *                                                                          *
  2469.  ****************************************************************************/
  2470.  
  2471. STATIC void ResizeWindow ( HWND hwnd ) {
  2472.  
  2473.   /**************************************************************************
  2474.    * Find the instance data.                                                *
  2475.    **************************************************************************/
  2476.  
  2477.    PDATA Data = PDATA ( WinQueryWindowPtr ( hwnd, QWL_USER ) ) ;
  2478.  
  2479.   /**************************************************************************
  2480.    * Determine how many items are to be displayed.                          *
  2481.    **************************************************************************/
  2482.  
  2483.    HPS hPS = WinGetPS ( hwnd ) ;
  2484.  
  2485.    int Count = 0 ;
  2486.    LONG Widest = 0 ;
  2487.    LONG Height = 0 ;
  2488.    Data->MaxColumns = 0 ;
  2489.  
  2490.    for ( int i=0; i<Data->IniData.ItemCount; i++ ) {
  2491.       Item *pItem = Data->IniData.Items[i].pItem ;
  2492.       if ( pItem->QueryFlag() ) {
  2493.          Count ++ ;
  2494.          RECTL Rectangle ;
  2495.          int Columns = pItem->Measure ( hPS, Rectangle ) ;
  2496.          Widest = max ( Widest, (Rectangle.xRight-Rectangle.xLeft+1) ) ;
  2497.          Height += Rectangle.yTop - Rectangle.yBottom ;
  2498.          Data->MaxColumns = max ( Data->MaxColumns, Columns ) ;
  2499.       } /* endif */
  2500.    } /* endfor */
  2501.  
  2502.    WinReleasePS ( hPS ) ;
  2503.  
  2504.   /**************************************************************************
  2505.    * If the window is visible and minimized, restore it invisibly.          *
  2506.    **************************************************************************/
  2507.  
  2508.    HWND Frame = WinQueryWindow ( hwnd, QW_PARENT ) ;
  2509.  
  2510.    BOOL fHadToHide = FALSE ;
  2511.    BOOL fHadToRestore = FALSE ;
  2512.    if ( Data->IniData.Position.fl & SWP_MINIMIZE ) {
  2513.       if ( WinIsWindowVisible ( Frame ) ) {
  2514.          WinShowWindow ( Frame, FALSE ) ;
  2515.          fHadToHide = TRUE ;
  2516.       } /* endif */
  2517.       WinSetWindowPos ( Frame, 0, 0, 0, 0, 0, SWP_RESTORE ) ;
  2518.       fHadToRestore = TRUE ;
  2519.    } /* endif */
  2520.  
  2521.   /**************************************************************************
  2522.    * Get the entire window's current size and position.                     *
  2523.    **************************************************************************/
  2524.  
  2525.    SWP Position ;
  2526.    WinQueryWindowPos ( Frame, &Position ) ;
  2527.  
  2528.    RECTL Rectangle = { Position.x, Position.y, Position.x+Position.cx, Position.y+Position.cy } ;
  2529.  
  2530.    WinCalcFrameRect ( Frame, &Rectangle, TRUE ) ;
  2531.  
  2532.   /**************************************************************************
  2533.    * Determine the anchor point.                                            *
  2534.    **************************************************************************/
  2535.  
  2536.    POINTL Anchor ;
  2537.    switch ( Data->IniData.AnchorCorner ) {
  2538.       case CORNER_BL:
  2539.       default:
  2540.          Anchor.x = Rectangle.xLeft ;
  2541.          Anchor.y = Rectangle.yBottom ;
  2542.          break;
  2543.       case CORNER_BR:
  2544.          Anchor.x = Rectangle.xRight ;
  2545.          Anchor.y = Rectangle.yBottom ;
  2546.          break;
  2547.       case CORNER_TL:
  2548.          Anchor.x = Rectangle.xLeft ;
  2549.          Anchor.y = Rectangle.yTop ;
  2550.          break;
  2551.       case CORNER_TR:
  2552.          Anchor.x = Rectangle.xRight ;
  2553.          Anchor.y = Rectangle.yTop ;
  2554.          break;
  2555.    } /* endswitch */
  2556.  
  2557.   /**************************************************************************
  2558.    * Determine the new window size (with frame).                            *
  2559.    **************************************************************************/
  2560.  
  2561.    Rectangle.xLeft = Rectangle.yBottom = 0 ;
  2562.    Rectangle.xRight = Widest ;
  2563.    Rectangle.yTop = Height ;
  2564.  
  2565.   /**************************************************************************
  2566.    * Determine the new rectangle.                                           *
  2567.    **************************************************************************/
  2568.  
  2569.    switch ( Data->IniData.AnchorCorner ) {
  2570.       case CORNER_BL:
  2571.       default:
  2572.          Rectangle.xRight = Anchor.x + ( Rectangle.xRight - Rectangle.xLeft ) ;
  2573.          Rectangle.xLeft = Anchor.x ;
  2574.          Rectangle.yTop = Anchor.y + ( Rectangle.yTop - Rectangle.yBottom ) ;
  2575.          Rectangle.yBottom = Anchor.y ;
  2576.          break;
  2577.       case CORNER_BR:
  2578.          Rectangle.xLeft = Anchor.x - ( Rectangle.xRight - Rectangle.xLeft ) ;
  2579.          Rectangle.xRight = Anchor.x ;
  2580.          Rectangle.yTop = Anchor.y + ( Rectangle.yTop - Rectangle.yBottom ) ;
  2581.          Rectangle.yBottom = Anchor.y ;
  2582.          break;
  2583.       case CORNER_TL:
  2584.          Rectangle.xRight = Anchor.x + ( Rectangle.xRight - Rectangle.xLeft ) ;
  2585.          Rectangle.xLeft = Anchor.x ;
  2586.          Rectangle.yBottom = Anchor.y - ( Rectangle.yTop - Rectangle.yBottom ) ;
  2587.          Rectangle.yTop = Anchor.y ;
  2588.          break;
  2589.       case CORNER_TR:
  2590.          Rectangle.xLeft = Anchor.x - ( Rectangle.xRight - Rectangle.xLeft ) ;
  2591.          Rectangle.xRight = Anchor.x ;
  2592.          Rectangle.yBottom = Anchor.y - ( Rectangle.yTop - Rectangle.yBottom ) ;
  2593.          Rectangle.yTop = Anchor.y ;
  2594.          break;
  2595.    } /* endswitch */
  2596.  
  2597.    WinCalcFrameRect ( Frame, &Rectangle, FALSE ) ;
  2598.  
  2599.   /**************************************************************************
  2600.    * Move and size the window.                                              *
  2601.    **************************************************************************/
  2602.  
  2603.    #ifdef DEBUG
  2604.    Log ( "Resize: Setting window position to %i,%i (%ix%i).",
  2605.       Rectangle.xLeft, Rectangle.yBottom,
  2606.       Rectangle.xRight-Rectangle.xLeft, Rectangle.yTop-Rectangle.yBottom ) ;
  2607.    #endif
  2608.  
  2609.    WinSetWindowPos ( Frame, 0, Rectangle.xLeft, Rectangle.yBottom,
  2610.       Rectangle.xRight-Rectangle.xLeft, Rectangle.yTop-Rectangle.yBottom,
  2611.       SWP_MOVE | SWP_SIZE ) ;
  2612.  
  2613.   /**************************************************************************
  2614.    * Return the window to its original state.                               *
  2615.    **************************************************************************/
  2616.  
  2617.    if ( fHadToRestore ) {
  2618.       #ifdef DEBUG
  2619.       Log ( "Resize: Restoring window position to %i,%i (%ix%i).",
  2620.          Data->IniData.Position.x, Data->IniData.Position.y,
  2621.          Data->IniData.Position.cx, Data->IniData.Position.cy ) ;
  2622.       #endif
  2623.       WinSetWindowPos ( Frame, 0,
  2624.          Data->IniData.Position.x, Data->IniData.Position.y,
  2625.          Data->IniData.Position.cx, Data->IniData.Position.cy,
  2626.          SWP_MOVE | SWP_SIZE | SWP_MINIMIZE ) ;
  2627.    } /* endif */
  2628.  
  2629.    if ( fHadToHide )
  2630.       WinShowWindow ( Frame, TRUE ) ;
  2631.  
  2632.   /**************************************************************************
  2633.    * Invalidate the window so that it gets repainted.                       *
  2634.    **************************************************************************/
  2635.  
  2636.    WinInvalidateRect ( hwnd, 0, TRUE ) ;
  2637. }
  2638.  
  2639. /****************************************************************************
  2640.  *                                                                          *
  2641.  *                      Hide Window Controls                                *
  2642.  *                                                                          *
  2643.  ****************************************************************************/
  2644.  
  2645. STATIC void HideControls ( BOOL fHide, HWND Frame, HWND SysMenu, HWND TitleBar, HWND MinMax ) {
  2646.  
  2647.   /**************************************************************************
  2648.    * Get original window position and state.                                *
  2649.    **************************************************************************/
  2650.  
  2651.    SWP OldPosition ;
  2652.    WinQueryWindowPos ( Frame, &OldPosition ) ;
  2653.  
  2654.    BOOL WasVisible = WinIsWindowVisible ( Frame ) ;
  2655.  
  2656.   /**************************************************************************
  2657.    * Restore and hide the window.                                           *
  2658.    **************************************************************************/
  2659.  
  2660.    WinSetWindowPos ( Frame, 0, 0, 0, 0, 0, SWP_RESTORE | SWP_HIDE ) ;
  2661.  
  2662.   /**************************************************************************
  2663.    * Determine client window and location.                                  *
  2664.    **************************************************************************/
  2665.  
  2666.    SWP Position ;
  2667.    WinQueryWindowPos ( Frame, &Position ) ;
  2668.  
  2669.    RECTL Rectangle ;
  2670.    Rectangle.xLeft   = Position.x ;
  2671.    Rectangle.xRight  = Position.x + Position.cx ;
  2672.    Rectangle.yBottom = Position.y ;
  2673.    Rectangle.yTop    = Position.y + Position.cy ;
  2674.  
  2675.    WinCalcFrameRect ( Frame, &Rectangle, TRUE ) ;
  2676.  
  2677.   /**************************************************************************
  2678.    * Hide or reveal the controls windows by changing their parentage.       *
  2679.    **************************************************************************/
  2680.  
  2681.    if ( fHide ) {
  2682.       WinSetParent ( SysMenu,  HWND_OBJECT, FALSE ) ;
  2683.       WinSetParent ( TitleBar, HWND_OBJECT, FALSE ) ;
  2684.       WinSetParent ( MinMax,   HWND_OBJECT, FALSE ) ;
  2685.    } else {
  2686.       WinSetParent ( SysMenu,  Frame, TRUE ) ;
  2687.       WinSetParent ( TitleBar, Frame, TRUE ) ;
  2688.       WinSetParent ( MinMax,   Frame, TRUE ) ;
  2689.    } /* endif */
  2690.  
  2691.   /**************************************************************************
  2692.    * Tell the frame that things have changed.  Let it update the window.    *
  2693.    **************************************************************************/
  2694.  
  2695.    WinSendMsg ( Frame, WM_UPDATEFRAME,
  2696.       MPFROMSHORT ( FCF_TITLEBAR | FCF_SYSMENU | FCF_MINBUTTON ), 0 ) ;
  2697.  
  2698.   /**************************************************************************
  2699.    * Reposition the frame around the client window, which is left be.       *
  2700.    **************************************************************************/
  2701.  
  2702.    WinCalcFrameRect ( Frame, &Rectangle, FALSE ) ;
  2703.  
  2704.    #ifdef DEBUG
  2705.    Log ( "HideControls: Setting window position to %i,%i (%ix%i).",
  2706.       Rectangle.xLeft, Rectangle.yBottom,
  2707.       Rectangle.xRight-Rectangle.xLeft, Rectangle.yTop-Rectangle.yBottom ) ;
  2708.    #endif
  2709.  
  2710.    WinSetWindowPos ( Frame, 0,
  2711.      Rectangle.xLeft,  Rectangle.yBottom,
  2712.      Rectangle.xRight - Rectangle.xLeft,
  2713.      Rectangle.yTop - Rectangle.yBottom,
  2714.      SWP_SIZE | SWP_MOVE ) ;
  2715.  
  2716.   /**************************************************************************
  2717.    * If window was maximized, put it back that way.                         *
  2718.    **************************************************************************/
  2719.  
  2720.    if ( OldPosition.fl & SWP_MAXIMIZE ) {
  2721.       #ifdef DEBUG
  2722.       Log ( "HideControls: Maximizing window position to %i,%i (%ix%i).",
  2723.          Rectangle.xLeft, Rectangle.yBottom,
  2724.          Rectangle.xRight-Rectangle.xLeft, Rectangle.yTop-Rectangle.yBottom ) ;
  2725.       #endif
  2726.       WinSetWindowPos ( Frame, 0,
  2727.         Rectangle.xLeft,  Rectangle.yBottom,
  2728.         Rectangle.xRight-Rectangle.xLeft,
  2729.         Rectangle.yTop-Rectangle.yBottom,
  2730.         SWP_SIZE | SWP_MOVE | ( OldPosition.fl & SWP_MAXIMIZE ) ) ;
  2731.    } /* endif */
  2732.  
  2733.   /**************************************************************************
  2734.    * If the window was visible in the first place, show it.                 *
  2735.    **************************************************************************/
  2736.  
  2737.    if ( WasVisible )
  2738.       WinShowWindow ( Frame, TRUE ) ;
  2739. }
  2740.  
  2741. /****************************************************************************
  2742.  *                                                                          *
  2743.  *    Update Window                                                         *
  2744.  *                                                                          *
  2745.  ****************************************************************************/
  2746.  
  2747. STATIC void UpdateWindow ( HWND hwnd, PDATA Data, BOOL All ) {
  2748.  
  2749.  /***************************************************************************
  2750.   * Determine how many items are to be displayed.                           *
  2751.   ***************************************************************************/
  2752.  
  2753.   int Count = 0 ;
  2754.   for ( int i=0; i<Data->IniData.ItemCount; i++ ) {
  2755.      Item *pItem = Data->IniData.Items[i].pItem ;
  2756.      if ( pItem->QueryFlag() ) {
  2757.         Count ++ ;
  2758.      } /* endif */
  2759.   } /* endfor */
  2760.  
  2761.  /***************************************************************************
  2762.   * Get presentation space and make it use RGB colors.                      *
  2763.   ***************************************************************************/
  2764.  
  2765.   HPS hPS = WinGetPS ( hwnd ) ;
  2766.   GpiCreateLogColorTable ( hPS, LCOL_RESET, LCOLF_RGB, 0, 0, 0 ) ;
  2767.  
  2768.  /***************************************************************************
  2769.   * Get the window's size and determine the initial position.               *
  2770.   ***************************************************************************/
  2771.  
  2772.   RECTL Rectangle ;
  2773.   WinQueryWindowRect ( hwnd, &Rectangle ) ;
  2774.  
  2775.   Rectangle.xLeft += Data->Width / 2 ;
  2776.   Rectangle.xRight -= Data->Width / 2 ;
  2777.  
  2778.   Rectangle.yBottom = Data->Height * ( Count - 1 ) ;
  2779.   Rectangle.yTop = Rectangle.yBottom + Data->Height ;
  2780.  
  2781.  /***************************************************************************
  2782.   * Review all items.  Display those changed, or all.                       *
  2783.   ***************************************************************************/
  2784.  
  2785.   for ( i=0; i<Data->IniData.ItemCount; i++ ) {
  2786.     Item *pItem = Data->IniData.Items[i].pItem ;
  2787.     if ( pItem->QueryFlag() ) {
  2788.       pItem->Repaint ( hPS, Rectangle, Data->IniData.TextColor, Data->IniData.BackColor, All ) ;
  2789.       Rectangle.yBottom -= Data->Height ;
  2790.       Rectangle.yTop    -= Data->Height ;
  2791.     } /* endif */
  2792.   } /* endfor */
  2793.  
  2794.  /***************************************************************************
  2795.   * Release the presentation space and return.                              *
  2796.   ***************************************************************************/
  2797.  
  2798.   WinReleasePS ( hPS ) ;
  2799. }
  2800.  
  2801.  
  2802. /****************************************************************************
  2803.  *                                                                          *
  2804.  *    Monitor Loop Thread                                                   *
  2805.  *                                                                          *
  2806.  ****************************************************************************/
  2807.  
  2808. STATIC VOID MonitorLoopThread ( PVOID Parameter ) {
  2809.  
  2810.   /**************************************************************************
  2811.    * Get the thread parameter.                                              *
  2812.    **************************************************************************/
  2813.  
  2814.    PMONITOR_PARMS Parms = PMONITOR_PARMS ( Parameter ) ;
  2815.  
  2816.   /**************************************************************************
  2817.    * Set this thread's priority.                                            *
  2818.    **************************************************************************/
  2819.  
  2820.    DosSetPriority ( PRTYS_THREAD, PRTYC_TIMECRITICAL, PRTYD_MAXIMUM, 0 ) ;
  2821.    DosSetPriority ( PRTYS_THREAD, PRTYC_TIMECRITICAL, PRTYD_MINIMUM+(*Parms->Priority), 0 ) ;
  2822.  
  2823.   /**************************************************************************
  2824.    * Start up the high resolution timer, if it is available.                *
  2825.    **************************************************************************/
  2826.  
  2827.    BOOL HiResTimer = OpenTimer ( ) ;
  2828.  
  2829.   /**************************************************************************
  2830.    * Loop while active . . .                                                *
  2831.    **************************************************************************/
  2832.  
  2833.    while ( Parms->Active ) {
  2834.  
  2835.      /***********************************************************************
  2836.       * Reset the last time and count seen.                                 *
  2837.       ***********************************************************************/
  2838.  
  2839.       ULONG LastMilliseconds ;
  2840.       TIMESTAMP Time [2] ;
  2841.  
  2842.       if ( HiResTimer )
  2843.          GetTime ( &Time[0] ) ;
  2844.       else
  2845.          DosQuerySysInfo ( QSV_MS_COUNT, QSV_MS_COUNT, &LastMilliseconds, sizeof(LastMilliseconds) ) ;
  2846.  
  2847.       ULONG LastCounter = *Parms->Counter ;
  2848.  
  2849.      /***********************************************************************
  2850.       * Let the counter count.                                              *
  2851.       ***********************************************************************/
  2852.  
  2853.       DosSleep ( *Parms->Interval ) ;
  2854.  
  2855.      /***********************************************************************
  2856.       * Find out how much time and counts went by.                          *
  2857.       ***********************************************************************/
  2858.  
  2859.       ULONG CurrentCounter = *Parms->Counter ;
  2860.  
  2861.       ULONG DeltaMilliseconds ;
  2862.  
  2863.       if ( HiResTimer ) {
  2864.          GetTime ( &Time[1] ) ;
  2865.  
  2866.          ULONG Nanoseconds ;
  2867.          DeltaMilliseconds = ComputeElapsedTime ( &Time[0], &Time[1], &Nanoseconds ) ;
  2868.  
  2869.          if ( Nanoseconds >= 500000 )
  2870.             DeltaMilliseconds ++ ;
  2871.       } else {
  2872.          ULONG Milliseconds ;
  2873.          DosQuerySysInfo ( QSV_MS_COUNT, QSV_MS_COUNT, &Milliseconds, sizeof(Milliseconds) ) ;
  2874.          DeltaMilliseconds = Milliseconds - LastMilliseconds ;
  2875.       } /* endif */
  2876.  
  2877.      /***********************************************************************
  2878.       * Find out how much idle time was counted.  Adjust it to persecond.   *
  2879.       ***********************************************************************/
  2880.  
  2881.       ULONG Counter = (ULONG) ( ( (double)(CurrentCounter-LastCounter) * 1000 ) / (double)DeltaMilliseconds ) ;
  2882.  
  2883.      /***********************************************************************
  2884.       * Tell the owner window to refresh its statistics.                    *
  2885.       ***********************************************************************/
  2886.  
  2887.       WinPostMsg ( Parms->Owner, WM_REFRESH, MPFROMLONG(Counter), 0 ) ;
  2888.  
  2889.    } /* endwhile */
  2890.  
  2891.    MonitorThreadEvent.Post ( ) ;
  2892. }
  2893.  
  2894. /****************************************************************************
  2895.  *                                                                          *
  2896.  *      Update the Item List to reflect changes in the available drives.    *
  2897.  *                                                                          *
  2898.  ****************************************************************************/
  2899.  
  2900. STATIC VOID UpdateDriveList ( HAB Anchor, HMODULE Library, HINI IniHandle,
  2901.    PINIDATA IniData, Dde_Server *pDdeServer, ULONG OldDrives, ULONG NewDrives ) {
  2902.  
  2903.  /***************************************************************************
  2904.   * Get format strings.                                                     *
  2905.   ***************************************************************************/
  2906.  
  2907.   ResourceString LabelFormat ( Library, IDS_DRIVE_FREE ) ;
  2908.  
  2909.  /***************************************************************************
  2910.   * Save the old item list for comparison.                                  *
  2911.   ***************************************************************************/
  2912.  
  2913.   ITEM OldItems [ ITEM_BASE_COUNT + MAX_DRIVES ] ;
  2914.  
  2915.   memset ( OldItems, 0, sizeof(OldItems) ) ;
  2916.  
  2917.   USHORT OldCount = 0 ;
  2918.   if ( OldDrives ) {
  2919.      OldCount = USHORT ( IniData->ItemCount ) ;
  2920.      memcpy ( OldItems, IniData->Items, sizeof(OldItems) ) ;
  2921.   } /* endif */
  2922.  
  2923.  /***************************************************************************
  2924.   * Add items for each drive on the system.                                 *
  2925.   ***************************************************************************/
  2926.  
  2927.   USHORT Count = ITEM_BASE_COUNT ;
  2928.   USHORT OldIndex = ITEM_BASE_COUNT ;
  2929.  
  2930.   ULONG Drives = 0 ;
  2931.   NewDrives >>= 2 ;
  2932.   OldDrives >>= 2 ;
  2933.  
  2934.   for ( int Drive=3; Drive<=MAX_DRIVES; Drive++ ) {
  2935.  
  2936.      while ( ( OldIndex < OldCount )
  2937.         AND ( (SHORT)OldItems[OldIndex].pItem->QueryId() < ITEM_BASE_COUNT + Drive ) ) {
  2938.         OldIndex ++ ;
  2939.      } /* endwhile */
  2940.  
  2941.      if ( NewDrives & 1 ) {
  2942.         if ( OldDrives & 1 ) {
  2943.            Drives |= ( 1 << (Drive-1) ) ;
  2944.            if ( ( OldIndex < OldCount )
  2945.               AND ( (SHORT)OldItems[OldIndex].pItem->QueryId() == ITEM_BASE_COUNT + Drive ) ) {
  2946.               IniData->Items[Count++] = OldItems[OldIndex++] ;
  2947.            } /* endif */
  2948.         } else {
  2949.            BYTE FileSystem [80] = { 0 } ;
  2950.            BYTE DiskLabel [12] = { 0 } ;
  2951.            int DriveType = CheckDrive ( USHORT(Drive), FileSystem, DiskLabel ) ;
  2952.            if ( DriveType ) {
  2953.  
  2954.               if ( DriveType > 0 )
  2955.                  Drives |= ( 1 << (Drive-1) ) ;
  2956.  
  2957.               char Name [80] ;
  2958.               sprintf ( Name,   "ShowDrive%c:", Drive+'A'-1 ) ;
  2959.  
  2960.               char Label [80] ;
  2961.               sprintf ( Label,  PCHAR(LabelFormat),  Drive+'A'-1 ) ;
  2962.  
  2963.               IniData->Items[Count++].pItem = new DriveFree ( USHORT(ITEM_BASE_COUNT+Drive),
  2964.                  Name, Label, Label,  pDdeServer, "Items",
  2965.                  IniData->CountryInfo, IniData->ShowK,
  2966.                  USHORT(Drive), IniData->DriveError,
  2967.                  IniData->ShowFileSystemNames, FileSystem,
  2968.                  IniData->ShowDiskLabels, DiskLabel ) ;
  2969.            } /* endif */
  2970.         } /* endif */
  2971.  
  2972.      } else {
  2973.         if ( OldDrives & 1 ) {
  2974.            delete OldItems[OldIndex++].pItem ;
  2975.         } else {
  2976.            // Do nothing.
  2977.         } /* endif */
  2978.      } /* endif */
  2979.  
  2980.      NewDrives >>= 1 ;
  2981.      OldDrives >>= 1 ;
  2982.  
  2983.   } /* endfor */
  2984.  
  2985.  /***************************************************************************
  2986.   * Save the new item count.                                                *
  2987.   ***************************************************************************/
  2988.  
  2989.   IniData->ItemCount = Count ;
  2990.  
  2991.  /***************************************************************************
  2992.   * Fetch the display flags for the drives.                                 *
  2993.   ***************************************************************************/
  2994.  
  2995.   for ( int i=ITEM_BASE_COUNT; i<IniData->ItemCount; i++ ) {
  2996.  
  2997.      BOOL Flag = TRUE ;
  2998.      Item *pItem = IniData->Items[i].pItem ;
  2999.      ULONG Size ;
  3000.  
  3001.      if ( PrfQueryProfileSize ( IniHandle, PSZ(PROGRAM_NAME), PSZ(pItem->QueryName()), &Size )
  3002.         AND ( ( Size == sizeof(Flag) ) OR ( Size == sizeof(short) ) )
  3003.         AND PrfQueryProfileData ( IniHandle, PSZ(PROGRAM_NAME), PSZ(pItem->QueryName()), &Flag, &Size ) ) {
  3004.  
  3005.      } /* endif */
  3006.  
  3007.      if ( Flag )
  3008.         pItem->SetFlag () ;
  3009.      else
  3010.         pItem->ResetFlag () ;
  3011.  
  3012.      char Tag [80] ;
  3013.      strcpy ( Tag, PCHAR(IniData->Items[i].pItem->QueryName()) ) ;
  3014.      strcat ( Tag, " Label" ) ;
  3015.      IniData->Items[i].fLabel = FALSE ;
  3016.      if ( PrfQueryProfileSize ( IniHandle, PSZ(PROGRAM_NAME), PSZ(Tag), &Size )
  3017.         AND ( Size == sizeof(IniData->Items[i].Label) )
  3018.         AND PrfQueryProfileData ( IniHandle, PSZ(PROGRAM_NAME), PSZ(Tag), &IniData->Items[i].Label, &Size )
  3019.         AND IniData->Items[i].Label[0] ) {
  3020.  
  3021.         IniData->Items[i].fLabel = TRUE ;
  3022.         IniData->Items[i].pItem->SetLabel ( IniData->Items[i].Label ) ;
  3023.  
  3024.      } /* endif */
  3025.  
  3026.   } /* endfor */
  3027.  
  3028.  /***************************************************************************
  3029.   * Update the total free space object.                                     *
  3030.   ***************************************************************************/
  3031.  
  3032.   ( (TotalFree*) IniData->Items [ ITEM_TOTALFREE ] . pItem ) -> ResetMask ( Drives ) ;
  3033. }
  3034.  
  3035. /****************************************************************************
  3036.  *                                                                          *
  3037.  *      Check to see if drive should be added to display list.              *
  3038.  *                                                                          *
  3039.  ****************************************************************************/
  3040.  
  3041. STATIC int CheckDrive ( USHORT Drive, PBYTE FileSystem, PBYTE DiskLabel ) {
  3042.  
  3043.   /**************************************************************************
  3044.    * First, check to see if drive is local or remote.  Remote drives are    *
  3045.    *   always monitored.                                                    *
  3046.    **************************************************************************/
  3047.  
  3048.    BYTE Path [3] ;
  3049.    Path[0] = (BYTE) ( Drive + 'A' - 1 ) ;
  3050.    Path[1] = ':' ;
  3051.    Path[2] = 0 ;
  3052.  
  3053.    DosError ( FERR_DISABLEHARDERR ) ;
  3054.  
  3055.    BYTE Buffer [1024] ;
  3056.    ULONG Size = sizeof(Buffer) ;
  3057.    ULONG Status = DosQueryFSAttach ( Path, 0, FSAIL_QUERYNAME, (PFSQBUFFER2)Buffer, &Size ) ;
  3058.    DosError ( FERR_ENABLEHARDERR ) ;
  3059.  
  3060.    if ( Status ) {
  3061.       #ifdef DEBUG
  3062.       Log ( "ERROR: Unable to query drive %s for file system.  Status %04X.", Path, Status ) ;
  3063.       #endif
  3064.       return ( 0 ) ;   // Don't monitor.
  3065.    } /* endif */
  3066.  
  3067.    USHORT cbName = PFSQBUFFER2(Buffer)->cbName ;
  3068.    strcpy ( PCHAR(FileSystem), PCHAR(PFSQBUFFER2(Buffer+cbName)->szFSDName) ) ;
  3069.  
  3070.    if ( PFSQBUFFER2(Buffer)->iType == FSAT_REMOTEDRV ) {
  3071.       return ( -1 ) ;  // Monitor but don't include in the total over all drives.
  3072.    } /* endif */
  3073.  
  3074.   /**************************************************************************
  3075.    * Attempt to open the local drive as an entire device.  If unable to do  *
  3076.    *   so, we cannot monitor this drive.                                    *
  3077.    **************************************************************************/
  3078.  
  3079.    ULONG Action ;
  3080.    HFILE Handle ;
  3081.    Status = DosOpen ( Path, &Handle, &Action, 0, 0, FILE_OPEN,
  3082.       OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE |
  3083.       OPEN_FLAGS_DASD | OPEN_FLAGS_FAIL_ON_ERROR, 0 ) ;
  3084.  
  3085.    if ( Status ) {
  3086.       #ifdef DEBUG
  3087.       Log ( "ERROR: Unable to open local drive %s.  Status %04X.", Path, Status ) ;
  3088.       #endif
  3089.       return ( 0 ) ;   // Don't monitor.
  3090.    } /* endif */
  3091.  
  3092.   /**************************************************************************
  3093.    * Check to see if the drive has removable media.  We cannot monitor such.*
  3094.    **************************************************************************/
  3095.  
  3096.    BOOL Addit = FALSE ;
  3097.    BYTE Command = 0 ;
  3098.    BYTE NonRemovable ;
  3099.  
  3100.    ULONG LengthIn = sizeof(Command) ;
  3101.    ULONG LengthOut = sizeof(NonRemovable);
  3102.  
  3103.    if ( NOT DosDevIOCtl ( Handle, 8, 0x20, &Command, sizeof(Command), &LengthIn,
  3104.       &NonRemovable, sizeof(NonRemovable), &LengthOut ) ) {
  3105.  
  3106.       Addit = NonRemovable ;
  3107.  
  3108.    } /* endif */
  3109.  
  3110.   /**************************************************************************
  3111.    * Close the drive.                                                       *
  3112.    **************************************************************************/
  3113.  
  3114.    DosClose ( Handle ) ;
  3115.  
  3116.   /**************************************************************************
  3117.    * Get the drive label.                                                   *
  3118.    **************************************************************************/
  3119.  
  3120.    FSINFO Info ;
  3121.    if ( DosQueryFSInfo ( Drive, FSIL_VOLSER, PBYTE(&Info), sizeof(Info) ) == 0 )
  3122.       strcpy ( PCHAR(DiskLabel), PCHAR(Info.vol.szVolLabel) ) ;
  3123.  
  3124.   /**************************************************************************
  3125.    * Return the final verdict.                                              *
  3126.    **************************************************************************/
  3127.  
  3128.    return ( int(Addit) ) ;    // Monitor and include in overall total if not removable.
  3129. }
  3130.  
  3131. /****************************************************************************
  3132.  *                                                                          *
  3133.  *                       Calibrate the Load Meter                           *
  3134.  *                                                                          *
  3135.  ****************************************************************************/
  3136.  
  3137. STATIC ULONG CalibrateLoadMeter ( PCOUNTER_PARMS Parms ) {
  3138.  
  3139.  /***************************************************************************
  3140.   * Set result to zero as a default.                                        *
  3141.   ***************************************************************************/
  3142.  
  3143.   double AdjustedMaxLoad = 0.0 ;
  3144.  
  3145.  /***************************************************************************
  3146.   * If HRTIMER.SYS has been installed . . .                                 *
  3147.   ***************************************************************************/
  3148.  
  3149.   if ( OpenTimer ( ) ) {
  3150.  
  3151.    /*************************************************************************
  3152.     * Increase this thread's priority to the maximum.                       *
  3153.     *************************************************************************/
  3154.  
  3155.     DosSetPriority ( PRTYS_THREAD, PRTYC_TIMECRITICAL, PRTYD_MAXIMUM, 0 ) ;
  3156.  
  3157.    /*************************************************************************
  3158.     * Create the calibration thread and set its priority next highest.      *
  3159.     *************************************************************************/
  3160.  
  3161.     CounterThreadEvent.Reset ( ) ;
  3162.     Parms->Active = TRUE ;
  3163.     TID tidCalibrate = StartThread ( "CounterThread", CounterThread, 0x3000, Parms ) ;
  3164.     DosSuspendThread ( tidCalibrate ) ;
  3165.     DosSetPriority ( PRTYS_THREAD, PRTYC_TIMECRITICAL, PRTYD_MAXIMUM, tidCalibrate ) ;
  3166.     DosSetPriority ( PRTYS_THREAD, PRTYC_TIMECRITICAL, -1, tidCalibrate ) ;
  3167.  
  3168.    /*************************************************************************
  3169.     * Reset the calibration count, get the time, and let the counter go.    *
  3170.     *************************************************************************/
  3171.  
  3172.     Parms->Counter = 0 ;
  3173.     TIMESTAMP Time[2] ;
  3174.     GetTime ( &Time[0] ) ;
  3175.     DosResumeThread ( tidCalibrate ) ;
  3176.  
  3177.    /*************************************************************************
  3178.     * Sleep for one second.                                                 *
  3179.     *************************************************************************/
  3180.  
  3181.     DosSleep ( 1000 ) ;
  3182.  
  3183.    /*************************************************************************
  3184.     * Suspend the calibration counter and get the time.                     *
  3185.     *************************************************************************/
  3186.  
  3187.     Parms->Active = FALSE ;
  3188.     CounterThreadEvent.Wait ( 10000 ) ;
  3189.     GetTime ( &Time[1] ) ;
  3190.  
  3191.    /*************************************************************************
  3192.     * Return priorities to normal.                                          *
  3193.     *************************************************************************/
  3194.  
  3195.     DosSetPriority ( PRTYS_THREAD, PRTYC_REGULAR, 0, 0 ) ;
  3196.  
  3197.    /*************************************************************************
  3198.     * Get the elapsed time and adjust the calibration count.                *
  3199.     *************************************************************************/
  3200.  
  3201.     ULONG Milliseconds ;
  3202.     ULONG Nanoseconds ;
  3203.     Milliseconds = ComputeElapsedTime ( &Time[0], &Time[1], &Nanoseconds ) ;
  3204.  
  3205.     AdjustedMaxLoad = (double)Parms->Counter * 1.0E9 ;
  3206.     AdjustedMaxLoad /= (double)Milliseconds*1.0E6L + (double)Nanoseconds ;
  3207.  
  3208.    /*************************************************************************
  3209.     * Close down the connection to HRTIMER.SYS.                             *
  3210.     *************************************************************************/
  3211.  
  3212.     CloseTimer ( ) ;
  3213.   }
  3214.  
  3215.  /***************************************************************************
  3216.   * Return the adjusted calibration count.  If HRTIMER was not there, it    *
  3217.   *   will be zero.                                                         *
  3218.   ***************************************************************************/
  3219.  
  3220.   return ( (ULONG)AdjustedMaxLoad ) ;
  3221. }
  3222.  
  3223. /****************************************************************************
  3224.  *                                                                          *
  3225.  *                    General Purpose Counter Thread                        *
  3226.  *                                                                          *
  3227.  ****************************************************************************/
  3228.  
  3229. STATIC VOID CounterThread ( PVOID Parameter ) {
  3230.  
  3231.   /*************************************************************************
  3232.    * Count like mad.                                                       *
  3233.    *************************************************************************/
  3234.  
  3235.    PCOUNTER_PARMS Parms = PCOUNTER_PARMS ( Parameter ) ;
  3236.    while ( Parms->Active ) {
  3237.       Parms->Counter ++ ;
  3238.    } /* endwhile */
  3239.  
  3240.    CounterThreadEvent.Post ( ) ;
  3241. }
  3242.  
  3243.